Category Archives: Programming

Elasticsearch cheat sheet


Check installed plugins on a node:

curl -XGET 'http://localhost:9200/_nodes/NODE_NAME/plugins?pretty=yes'


Check shards recovery:

curl -XGET http://localhost:9200/_cat/recovery

Check shards status:

curl -XGET http://localhost:9200/_cat/shards

Deactivate/Activate dynamic rellocation:

curl -XPUT localhost:9200/_cluster/settings -d '{ "transient" : { "cluster.routing.allocation.enable" : "none" } }'
curl -XPUT 'localhost:9200/_cluster/settings' -d '{ "transient" : { "cluster.routing.allocation.enable" : "all" } }'

Relocating shard:

curl -XPOST 'localhost:9200/_cluster/reroute' -d '{
        "commands" : [ {
              "allocate" : {
                  "index" : "INDEX_NAME", 
                  "shard" : SHARD_NUMBER, 
                  "node" : "NODE", 
                  "allow_primary" : true


Check cluster health:

curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'

Check pending tasks:

curl -XGET 'http://localhost:9200/_cluster/pending_tasks&pretty=true'

List nodes:

curl -XGET 'http://localhost:9200/_cat/nodes?v'


Set replica count:

curl -XPUT 'localhost:9200/my_index/_settings' -d ' 
  "index" : { "number_of_replicas" : 4 } 


List indexes:

curl 'localhost:9200/_cat/indices?v'

Delete index:

curl -XDELETE 'http://localhost:9200/twitter/'


Debugging startup problems:

Add a line into /etc/init.d/elasticsearch to print out the the start command:

# Start Daemon
log_daemon_msg "sudo -u $ES_USER $DAEMON $DAEMON_OPTS"    # <-- Add this line
start-stop-daemon --start -b --user "$ES_USER" -c "$ES_USER" --pidfile "$PID_FILE" --exec $DAEMON -- $DAEMON_OPTS
log_end_msg $?

Installing pyhash in Mac OSX (using pip and brew)

If you are trying to install pyhash (0.6.2) on Mac OS X 10.10 you might get the following error:

src/Hash.h:20:20: error: __int128 is not supported on this target typedef unsigned __int128 uint128_t;

Try to run the install command in the following way:

ARCHFLAGS="-arch x86_64" pip install pyhash

If you are still having problems regarding a boost library missing,

ld: library not found for -lboost_python-mt

You can use brew to install it.

brew install boost-python

You might need too install bsddb3 package also with pip if it complains that the library is missing.

pip install bsddb3

Inserting text in the middle of a line with AWK

Maybe I was not searching for the right terms but I had a bit of hard time to find how to this on the internet. Most of the solutions are about writing either in the line above or below the target line. I wanted to write text on the middle of a JSON object. Bear in mind I ain’t no AWK or SED wizard, I just started using AWK and there is probably far more efficient ways of doing this, I just couldn’t find them.

Continue reading Inserting text in the middle of a line with AWK

diyes: practical modeling of aggregates

I decided to start working on a simple example, a bank application, that shows how aggregates can be modeled using Diyes.

The aggregate I decided to model is a bank account, it will exemplify some basic concepts of aggregate modeling. First of, we create a class that inherits from AbstractAggregate

public class Account : AbstractAggregate

How we normally go about modeling aggregates is we expose methods which are the commands that can be performed on our aggregates. So in this case I decided to have an Open, a Deposit and a Withdraw method. First thing we do in these methods is checking the preconditions for their execution, if the preconditions are met, we apply an event describing what happened. Continue reading diyes: practical modeling of aggregates

diyes: laying the foundation

For the more lazy ones that decided to skip the event sourcing literature that I suggested in my first post, I will try to explain a bit of how it works. Bear in mind, I am myself try to get to understand better how  Event Sourcing (ES) and CQRS so my explanations might not be the best.

So basically, instead of having objects containing a state to represent our business objects, with event sourcing we have a sequence of events that describe what happened to our aggregates (in ES these business objects are called aggregates).

Continue reading diyes: laying the foundation

diyes: the event sourcing library

So the other day I was thinking to myself I wanted to know a bit more about event sourcing (ES) and the Command Query Responsibility Segregation pattern (CQRS). I have used ES before in a project before but I used library which was’t made by me. This gave me knowledge on how to model a domain using events but it didn’t give me the “down to the iron” experience of it. So I thought, what better way to learn about ES than by implementing a ES library myself.

Continue reading diyes: the event sourcing library