Elasticsearch Cheatsheet - Command Reference

All essential Elasticsearch commands organized by use case, with 40+ entries you can copy and run directly. Find the right command fast when you need it.

SysOps·40 commands·Last updated 2026-07-21
Back to SysOps

Cluster Status 6

curl localhost:9200/_cluster/health?pretty
Show green/yellow/red status and shard counts
curl localhost:9200/_cat/nodes?v
Show node roles, disk and load
curl localhost:9200/_cat/health?v
Cluster health overview (monitored often)
curl localhost:9200/_cluster/stats?pretty
Summary of indices, docs, shards
curl localhost:9200/_cat/allocation?v
Disk & shard allocation per node (watermark alarms)
curl localhost:9200/_cat/master?v
Show current master node (check first on split-brain)

Shard & Index 6

curl localhost:9200/_cat/indices?v
List all indices with health, docs, size
curl localhost:9200/_cat/shards?v&h=index,shard,prirep,state,node,unassigned.reason
Show shard distribution and unassigned reason
curl localhost:9200/_cluster/allocation/explain?pretty
Explain why a shard is unassigned (RED debugging)
curl -XDELETE localhost:9200/<index>
Delete index (confirm name first)
curl localhost:9200/_ilm/explain/<index>?pretty
Show ILM policy phase for an index
curl -XPUT localhost:9200/<index>/_settings -H "Content-Type:application/json" -d '{"number_of_replicas":1}'
Dynamically change replica count (yellow fix)

Document CRUD 6

curl -XPOST localhost:9200/<index>/_doc -d '{"name":"tom"}' -H "Content-Type:application/json"
Insert doc, auto-generate _id
curl -XPUT localhost:9200/<index>/_doc/1 -d '{"name":"tom"}' -H "Content-Type:application/json"
Insert/overwrite doc with explicit _id
curl -XPOST localhost:9200/<index>/_update/1 -d '{"doc":{"age":20}}' -H "Content-Type:application/json"
Partial update of a field
curl -XDELETE localhost:9200/<index>/_doc/1
Delete one doc by _id
curl -XPOST localhost:9200/<index>/_bulk -d '{"index":{"_id":"1"}} {"name":"a"} ' -H "Content-Type:application/x-ndjson"
Bulk write, newline-delimited, far faster than single
curl localhost:9200/<index>/_doc/1?pretty
Get doc by _id (add _source to see source only)

Aggregation 5

curl localhost:9200/<index>/_search -d '{"size":0,"aggs":{"by_status":{"terms":{"field":"status"}}}}' -H "Content-Type:application/json"
terms group aggregation (size:0 hides docs)
curl localhost:9200/<index>/_search -d '{"size":0,"aggs":{"avg_age":{"avg":{"field":"age"}}}}' -H "Content-Type:application/json"
avg (also sum/max/min)
curl localhost:9200/<index>/_search -d '{"size":0,"aggs":{"sales":{"date_histogram":{"field":"created_at","calendar_interval":"1d"}}}}' -H "Content-Type:application/json"
Date histogram bucket (1d/1M/1y)
curl localhost:9200/<index>/_search -d '{"size":0,"aggs":{"price_ranges":{"range":{"field":"price","ranges":[{"to":100},{"from":100,"to":500},{"from":500}]}}}}' -H "Content-Type:application/json"
Numeric range bucket stats
curl localhost:9200/<index>/_search -d '{"size":0,"aggs":{"users":{"cardinality":{"field":"user_id"}}}}' -H "Content-Type:application/json"
cardinality distinct count (approx, HyperLogLog)

Query & Slowlog 5

curl localhost:9200/<index>/_count?pretty
Count docs in an index
curl localhost:9200/_nodes/stats/thread_pool?pretty
Inspect thread-pool queue & rejected
curl localhost:9200/_nodes/stats/breaker?pretty
Check circuit breaker (large query failures)
tail -f /var/log/elasticsearch/*_index_search_slowlog.json
Follow slow query log
curl localhost:9200/<index>/_settings?pretty
Show index settings (replicas/shards)

Disk & Ops 6

curl localhost:9200/_cluster/settings?pretty
Show cluster dynamic settings (disk watermarks)
curl -XPUT localhost:9200/_cluster/settings -H "Content-Type:application/json" -d '{"transient":{"cluster.routing.allocation.disk.watermark.low":"85%"}}'
Temporarily adjust disk watermark (use with care)
curl -XPOST localhost:9200/_forcemerge?max_num_segments=1
Force merge segments (lower disk for read-only index)
df -h /var/lib/elasticsearch
Check ES data disk usage (writes blocked past watermark)
curl -XPOST localhost:9200/<index>/_close
Close index to free resources; open to restore
curl -XPOST localhost:9200/<index>/_refresh
Manually refresh so recent writes are searchable

💡 Tips

  • 集群变 red 先用 _cat/shards 找未分配分片,再用 allocation/explain 看原因,别急着强制分配。
  • 查询变慢先区分是 filter 没走缓存还是聚合基数过高,深分页用 search_after 替代 from+size。
  • 磁盘超 flood watermark 会拒绝写入,先清冷索引或调水位线,而不是直接加节点。
  • text 字段用 match 做全文检索,keyword 字段用 term 精确匹配,混用会导致查不到结果。
  • 批量写入用 _bulk 接口,比逐条 _doc 快一个数量级,注意 Content-Type 是 application/x-ndjson。

Official References

Commands are compiled from the official docs below. Click to verify the latest usage.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Found an error? Report it

Wrong command or description? Open an issue to help us fix it.

Found an error? Report it