Elasticsearch Reference Card
Jump to navigation
Jump to search
1 OVERVIEW
- get version and details
curl -XGET 'http://localhost:9200'
2 CLUSTER
curl 'http://localhost:9200/_cluster/health?pretty' curl 'http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=50s&pretty' curl 'http://localhost:9200/_cluster/state?pretty' curl 'http://localhost:9200/_cluster/stats?human&pretty' curl 'http://localhost:9200/_cluster/pending_tasks?pretty'
- full settings
curl 'http://localhost:9200/_cluster/settings?include_defaults=true&flat_settings=true&pretty'
3 ADMIN
- force a synced flush
curl -XPOST 'localhost:9200/_flush/synced'
- Change the number of shards being recovered simultaneously per node
curl -XPUT localhost:9200/_cluster/settings -d '{
"transient" :{
"cluster.routing.allocation.exclude._ip" : "1.2.3.4"
}
}';echo
- Change the recovery speed
curl -XPUT localhost:9200/_cluster/settings -d '{
"transient" :{
"indices.recovery.max_bytes_per_sec" : "80mb"
}
}';echo
- Change the number of concurrent streams for a recovery on a single node
curl -XPUT localhost:9200/_cluster/settings -d '{
"transient" :{
"indices.recovery.concurrent_streams" : 6
}
}';echo
4 NODE
- get infos
curl 'http://localhost:9200/_nodes?pretty' curl 'http://localhost:9200/_nodes/stats?pretty' curl 'http://localhost:9200/_nodes/nodeId1,nodeId2/stats?pretty'
- remove nodes from clusters gracefully
curl -XPUT localhost:9200/_cluster/settings -d '{
"transient" :{
"cluster.routing.allocation.exclude._ip" : "1.2.3.4"
}
}';echo
5 INDICES
- list
curl -X GET 'http://localhost:9200/_cat/indices?v'
- delete
curl -X DELETE 'http://localhost:9200/examples'
- back up
curl -XPOST --header 'Content-Type: application/json' http://localhost:9200/_reindex -d '{
"source": {
"index1": "someexamples"
},
"dest": {
"index2": "someexamples_copy"
}
}'
- list all docs in an index
curl -X GET 'http://localhost:9200/elasticsearch_query_examples/_search'
6 SHRADS
- move shards from one node to another
curl -XPOST 'http://localhost:9200/_cluster/reroute' -d '{
"commands" : [
{
"move" :
{
"index" : "indexname", "shard" : 1,
"from_node" : "nodename", "to_node" : "nodename"
}
}
]
}';echo
- force the allocation of an unassigned shard with a reason
curl -XPOST 'http://localhost:9200/_cluster/reroute?explain' -d '{
"commands" : [ {
"allocate" : {
"index" : "indexname", "shard" : 0, "node" : "nodename"
}
} ]
}';echo
6.1 Delete Unassigned Shrads
curl http://localhost:9200/_cluster/health?pretty
curl -XGET localhost:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason
curl -XGET http://localhost:9200/_cat/shards | grep UNASSIGNED | awk {'print $1'} | xargs -i curl -XDELETE "http://localhost:9200/{}"
curl -XGET localhost:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason
curl http://localhost:9200/_cluster/health?pretty