Elasticsearch curl commands and references

A collection of Elasticsearch curl commands and references.

Get Cluster Health

cluster health:

curl -s http://localhost:9200/_cluster/health?pretty

Get indices

indices:

curl -s http://localhost:9200/_cat/indices

Get shards

shards:

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

Stuck Unassigned Shards

Sometimes shards fail to assign and they hit a maximum retry. For example, say there’s a replica shard that is unassigned and won’t assign. Running this command has it retry:

curl -s -XPOST 'localhost:9200/_cluster/reroute?retry_failed' -H 'Content-Type: application/json' -d'
{
    "commands" : [
        {
          "allocate_replica" : {
                "index" : "INDEXNAME", "shard" : 0,
                "node" : "NODENAME"
          }
        }
    ]
}
'

In the above example, INDEXNAME is the index, NODENAME is the node. Also, the shard is shard 0.

Update Indices to Modify Replication

In some cases, an index is created with no replicas. To modify the index, run:

curl -s -XPUT 'localhost:9200/INDEXNAME/_settings?pretty' -H 'Content-Type: application/json' -d'
{
    "index" : {
        "number_of_replicas" : 1
    }
}
'

The above will update the INDEXNAME index to a replica of 1 (so 1 master, 1 replica).