Elasticsearch Reference Card

From Bitbull Wiki
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'

2.1 Disk filling

Add or modify the following lines in `elasticsearch.yml` to set the desired disk watermark levels and their corresponding percentages:

cluster.routing.allocation.disk.watermark.low: 85%
cluster.routing.allocation.disk.watermark.high: 90%
cluster.routing.allocation.disk.watermark.flood_stage: 95%
  • low
Elasticsearch starts allocating new shards to nodes with disk usage below this level.
  • high
Elasticsearch starts throttling shard allocations to nodes with disk usage above this level.
  • flood_stage
Elasticsearch prevents shard allocations on nodes with disk usage above this level.

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'
curl 'http://localhost:9200/_cat/nodes?v=true'
  • 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"
  }
}'
  • change replica count of an Indice
curl -XPUT --header 'Content-Type: application/json' 'http://localhost:9200/_index_name_/_settings' -d '{
  "index" : {
    "number_of_replicas" : 1
  }
}'
  • change replica count of all indices
curl -X PUT "127.0.0.1:9200/.*/_settings" -H 'Content-Type: application/json' -d'{ "index" : { "number_of_replicas" : 0 } }'


  • list all docs in an index
curl -X GET 'http://localhost:9200/elasticsearch_query_examples/_search'

6 SHRADS

  • list shrads
curl -XGET localhost:9200/_cat/shards?v
  • show details of a shard
curl -X GET 'http://localhost:9200/_cat/shards/graylog_39?v'
  • 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