Skip to content

Instantly share code, notes, and snippets.

@pfigue
Last active February 16, 2020 21:30
Show Gist options
  • Save pfigue/79fa468ed97fe963796d to your computer and use it in GitHub Desktop.
Save pfigue/79fa468ed97fe963796d to your computer and use it in GitHub Desktop.
ElasticSearch API

Useful ElasticSearch API methods in the command line

Check cluster health (how many nodes are up?):

curl -s -XGET "http://127.0.0.1:9200/_cluster/health?pretty=true" | jq .

Check cluster nodes names:

curl -s -XGET 'http://localhost:9200/_nodes' | jq '.nodes[].name'

Create a new index named kibana-int:

curl -XPOST 'http://localhost:9200/kibana-int'

Show stats for an index named kibana-int:

curl -XGET "http://localhost:9200/kibana-int/_stats" | jq '.'

Show a list with all indexes:

curl -s "http://localhost:9200/_stats" | jq ' .indices' | jq 'keys'

Show info about the processes in the nodes, like number of used FDs:

curl -s "http://127.0.0.1:9200/_nodes/process?pretty"

Run ES but do not daemonize:

/usr/share/elasticsearch/bin/elasticsearch -p /var/run/elasticsearch.pid --default.config=/etc/elasticsearch/elasticsearch.yml --default.path.home=/usr/share/elasticsearch --default.path.log/var/log/elasticsearch --default.path.data=/var/lib/elasticsearch --default.path.work=/tmp/elasticsearch --default.path.conf=/etc/elasticsearch -Des.max-open-files=true

jq filters

Number of replicas for logstash-2014.10.30 index:

."logstash-2014.10.30".settings.index.number_of_replicas

Sections of the logstash-2014.10.30 index answer document:

."logstash-2014.10.30"|keys
@jnovack
Copy link

jnovack commented Nov 2, 2015

To see all empty (zero document) indices:

curl -XGET "http://localhost:9200/_stats" | jq '[.indices|path(.[]|select(.primaries.docs.count == 0))|.[0]]'

@jnovack
Copy link

jnovack commented Nov 2, 2015

Show me indices with greater than 100 segments and their segment counts.

curl -XGET "http://localhost:9200/_stats" | jq '[ ( .indices | (path(.[]|select(.total.segments.count > 100)) |.[0]) ) as $index | { ($index): .indices[$index].total.segments.count } ]'

@turtlemonvh
Copy link

Thanks for this!

Here's another: heap per node

curl -s -X GET "http://localhost:9200/_nodes/stats" | jq '.nodes[] | .host as $host | .jvm.mem.heap_max_in_bytes | {"bytes": ., "host": $host }' -c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment