Difference between revisions of "Elasticsearch Reference Card"

From Bitbull Wiki
Jump to navigation Jump to search
Line 3: Line 3:
 
  curl -XGET 'http://localhost:9200'
 
  curl -XGET 'http://localhost:9200'
  
=CLUSTER AND NODE=
+
=CLUSTER=
 
  curl 'http://localhost:9200/_cluster/health?pretty'
 
  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/health?wait_for_status=yellow&timeout=50s&pretty'
Line 9: Line 9:
 
  curl 'http://localhost:9200/_cluster/stats?human&pretty'
 
  curl 'http://localhost:9200/_cluster/stats?human&pretty'
 
  curl 'http://localhost:9200/_cluster/pending_tasks?pretty'
 
  curl 'http://localhost:9200/_cluster/pending_tasks?pretty'
 +
 +
* full settings
 +
curl 'http://localhost:9200/_cluster/settings?include_defaults=true&flat_settings=true&pretty'
 +
 +
=ADMIN=
 +
* force a synced flush
 +
curl -XPOST 'localhost:9200/_flush/synced'
 +
 +
* Change the number of shards being recovered simultaneously per node
 +
<pre>
 +
curl -XPUT localhost:9200/_cluster/settings -d '{
 +
"transient" :{
 +
"cluster.routing.allocation.exclude._ip" : "1.2.3.4"
 +
}
 +
}';echo
 +
</pre>
 +
 +
* Change the recovery speed
 +
<pre>
 +
curl -XPUT localhost:9200/_cluster/settings -d '{
 +
"transient" :{
 +
"indices.recovery.max_bytes_per_sec" : "80mb"
 +
}
 +
}';echo
 +
</pre>
 +
 +
* Change the number of concurrent streams for a recovery on a single node
 +
<pre>
 +
curl -XPUT localhost:9200/_cluster/settings -d '{
 +
"transient" :{
 +
"indices.recovery.concurrent_streams" : 6
 +
}
 +
}';echo
 +
</pre>
 +
 +
=NODE=
 +
 +
* get infos
 
  curl 'http://localhost:9200/_nodes?pretty'
 
  curl 'http://localhost:9200/_nodes?pretty'
 
  curl 'http://localhost:9200/_nodes/stats?pretty'
 
  curl 'http://localhost:9200/_nodes/stats?pretty'
 
  curl 'http://localhost:9200/_nodes/nodeId1,nodeId2/stats?pretty'
 
  curl 'http://localhost:9200/_nodes/nodeId1,nodeId2/stats?pretty'
  
* full settings
+
* remove nodes from clusters gracefully
curl 'http://localhost:9200/_cluster/settings?include_defaults=true&flat_settings=true&pretty'
+
<pre>
 +
curl -XPUT localhost:9200/_cluster/settings -d '{
 +
"transient" :{
 +
"cluster.routing.allocation.exclude._ip" : "1.2.3.4"
 +
}
 +
}';echo
 +
</pre>
 +
 
 +
[[Category:Elastic]]
  
 
=INDICES=
 
=INDICES=

Revision as of 06:48, 6 November 2021

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