Skip to content

elasticsearch

Commands

nodes

# get nodes
curl -X GET "http://elastic:password@localhost:9200/_cat/nodes?h=name,ip,node.role,master" | sort

indices

# show all indexes
curl "http://elastic:password@localhost:9200/_cat/indices?v"

# show health
curl -X GET "http://localhost:9200/_cluster/health?pretty"

# list indices by size
curl "http://elastic:password@localhost:9200/_cat/indices?pretty&s=store.size:desc"

# remove index
curl -X DELETE "http://elastic:password@localhost:9200/metrics-2024.06?pretty"

shards

# show all shards 
curl -k http://elastic:password@localhost:9200/_cat/shards?pretty

curl -X POST "http://<elasticsearch_host>:9200/_cluster/reroute" -H 'Content-Type: application/json' -d '{
  "commands": [
    {
      "allocate_stale_primary": {
        "index": "<index_name>",
        "shard": 0,
        "node": "<node_name>",
        "accept_data_loss": false
      }
    }
  ]
}'

# show allocation for unassigned shards
curl "http://elastic:password@localhost:9200/_cluster/allocation/explain?pretty"

Heap Size

Shrinking an index

Show all indices

Reindex