Elastic search

Searching for something? Pun intended.

Useful commands

Status information

General health and shards status

$ curl -XGET http://localhost:9200/_cat/shards
haystack 2 p STARTED 1948 1.3mb 0.0.0.0 Galaxy Master
haystack 4 p STARTED 1983 1.3mb 0.0.0.0 Galaxy Master
haystack 3 p STARTED 1888 1.3mb 0.0.0.0 Galaxy Master
haystack 1 p STARTED 1919 1.3mb 0.0.0.0 Galaxy Master
haystack 0 p STARTED 1963 1.3mb 0.0.0.0 Galaxy Master

$ curl -XGET http://localhost:9200/_cluster/health?pretty

{
  "cluster_name" : "elasticsearch",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 5,
  "active_shards" : 5,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}

Fixing unassigned shards

I ran into unassigned shards issue when I was trying to launch two Elastic Search ( various versions 2.0 and 1.7) instances on one server - Elastic Search 1.7 was trying to allocate it's shards on second instance.Solution was a manually reallocating shards to correct instance:

curl -XPOST "http://localhost:19200/_cluster/reroute?explain" -d'
{
  "commands": [
    {
      "allocate": {
        "index": "graylog2_0",
        "shard": 0,
        "node": "A9kNlNvER4KpSjW93kWmgQ",
        "allow_primary": true
      }      
    }
  ]
}'

In my configuration I have two instanes running - one on port 9200, second 19200 (version 1.7, for use with GrayLog2).

During my Elastic Search voyages I have found this link https://t37.net/how-to-fix-your-elasticsearch-cluster-stuck-in-initializing-shards-mode.html extremely helpful.