Elasticsearch cheat sheet

PLUGINS

Check installed plugins on a node:

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

SHARDS

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
              }
            }
        ]
    }'

CLUSTER

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'

INDEX

Set replica count:

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

Reference

List indexes:

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

Delete index:

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

MISC

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 is dead?

If you were following my blog you might have noticed there was not much activity in the Event Sourcing framework I was doing in my free time. The main reason for this is that some time ago I decided to change job and will work as a DevOps Engineer at Unsilo, so I started focusing on using my free time in something more relevant for my next job. Very soon I will also loose my Windows box so I will not be able to code C# more so I think unfortunately I will have to leave this project midways…

If you are looking for CQRS library with a very active community try to check out d60 Cirqus, developed by my soon to be ex-colleagues down at d60.

#NoEstimates, Programmer Anarchy and Mob Programming

The Agile Manifesto has been written 13 years ago with the intention of changing the way software development projects were executed at the time. It prescribed the following:

Individuals and interactions over processes and tools
Working software over comprehensive documentation
Customer collaboration over contract negotiation
Responding to change over following a plan

Shortly after a few software development methodologies were fleshed out based on the agile manifesto mantras, probably the most notable are XP and SCRUM. While these two are massively adopted by almost all the software companies in the world (I swear I don’t remember seeing a IT job advertisement without mentioning SCRUM), some new trends that I consider interesting are starting to emerge like #NoEstimates, Programmer Anarchy and Mob Programming.

Continue reading #NoEstimates, Programmer Anarchy and Mob Programming

book review: The Passionate Programmer by Chad Fowler

I first heard of The Passionate Programmer about 1 year ago through Rasmus (@rasmuschristens), my team lead at that time, he recommended the book after hearing Chad Fowler in a conference and described it as highly inspiring. After all this time, I finally found some time to read it, and I must say I was also inspired. 

Continue reading book review: The Passionate Programmer by Chad Fowler

goto aarhus: looking forward to GOTO conference in Aarhus – day one

With less than one month for the conference, I am really starting to look forward to it. This will be the first non academic conference I will attend and some of the topics look really interesting. I’ve been lucky enough to get a blogger pass to the conference, this means there will definitely be more posts about it. Continue reading goto aarhus: looking forward to GOTO conference in Aarhus – day one

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