Effortless ElasticSearch clustering

1 2 Page 2
Page 2 of 2

Note the cluster_name is by default elasticsearch – you can change this name as well. Also, by default, the master node will claim the 9200 port, however, you can run that same command against any node (for example, http://localhost:9201/_cluster/nodes?pretty=true will respond with the same exact response).

You can check the health of a cluster, as well, by running this command:

cURL to ascertain cluster health
<span class='line-number'>1</span>
<code class='bash'><span class='line'>curl -XGET <span class="s1">'http://localhost:9200/_cluster/health?pretty=true'</span>

And you should see another JSON response like:

ElasticSearch cluster health
<span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<code class='json'><span class='line'><span class="p">{</span>
</span><span class='line'>  <span class="nt">"active_primary_shards"</span> <span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
</span><span class='line'>  <span class="nt">"active_shards"</span> <span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
</span><span class='line'>  <span class="nt">"cluster_name"</span> <span class="p">:</span> <span class="s2">"elasticsearch"</span><span class="p">,</span>
</span><span class='line'>  <span class="nt">"initializing_shards"</span> <span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
</span><span class='line'>  <span class="nt">"number_of_data_nodes"</span> <span class="p">:</span> <span class="mi">3</span><span class="p">,</span>
</span><span class='line'>  <span class="nt">"number_of_nodes"</span> <span class="p">:</span> <span class="mi">3</span><span class="p">,</span>
</span><span class='line'>  <span class="nt">"relocating_shards"</span> <span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
</span><span class='line'>  <span class="nt">"status"</span> <span class="p">:</span> <span class="s2">"green"</span><span class="p">,</span>
</span><span class='line'>  <span class="nt">"timed_out"</span> <span class="p">:</span> <span class="kc">false</span><span class="p">,</span>
</span><span class='line'>  <span class="nt">"unassigned_shards"</span> <span class="p">:</span> <span class="mi">0</span>
</span><span class='line'><span class="p">}</span>

Nodes a cluster will elect a new master if your master node goes down. For example, if you go into the master node terminal window and control-c the process, you should see the two other nodes quickly recognize the master’s failure and consequently elect one of themselves as the new master:

A new master is elected
<span class='line-number'>1</span>
<span class='line-number'>2</span>
<code class='bash'><span class='line'><span class="o">[</span>discovery.zen<span class="o">]</span> <span class="o">[</span>Caiera<span class="o">]</span> master_left <span class="o">[[</span>Dionysus<span class="o">][</span>r7gbosdKSWGfTCgRPrS6vw<span class="o">][</span>inet<span class="o">[</span>/<span class="o">]]]</span>, reason <span class="o">[</span>shut_down<span class="o">]</span>
</span><span class='line'><span class="o">[</span>cluster.service<span class="o">]</span> <span class="o">[</span>Caiera<span class="o">]</span> master <span class="o">{</span>new <span class="o">[</span>Caiera<span class="o">][</span>Eh3DHlcRQhGxatGnUG8smA<span class="o">][</span>inet<span class="o">[</span>/<span class="o">]]</span>, previous <span class="o">[</span>Dionysus<span class="o">][</span>r7gbosdKSWGfTCgRPrS6vw<span class="o">][</span>inet<span class="o">[</span>/<span class="o">]]}</span>, removed <span class="o">{[</span>Dionysus<span class="o">][</span>r7gbosdKSWGfTCgRPrS6vw<span class="o">][</span>inet<span class="o">[</span>/<span class="o">]]</span>,<span class="o">}</span>, reason: zen-disco-master_failed <span class="o">([</span>Dionysus<span class="o">][</span>r7gbosdKSWGfTCgRPrS6vw<span class="o">][</span>inet<span class="o">[</span>/<span class="o">]])</span>

Remember, ElasticSearch will make intelligent defaults for you, however, you should most likely look closely at the various aspects you can configure when it comes to clustering. For example, cluster name and node names are something you should consider implementing.

What’s more, the process of discovery can be configured. For instance, multicast is used for auto-discovery, however, there are other options available, such as unicast, which allows you to specify which nodes can be a part of a cluster (that is, unknown nodes cannot join).

Finally, you can control how nodes operate in a cluster. You can explicitly forbid a node from being a master, for example, and you can also configure nodes to not hold data (thus, those nodes become veritable routers for searches). These options allow you to create an interesting topology that has some intelligent routing built in.

Regardless of how you configure an ElasticSearch cluster, I hope you’ve seen that it couldn’t be any easier. Can you dig it, man?

This story, "Effortless ElasticSearch clustering" was originally published by JavaWorld.


Copyright © 2013 IDG Communications, Inc.

1 2 Page 2
Page 2 of 2