package elasticsearch-cli

  1. Overview
  2. Docs
Command-line client for Elasticsearch







Published: 08 Apr 2019


elasticsearch-cli — Command-line client for Elasticsearch

This project provides a command line tool to query ElasticSearch clusters.


elasticsearch-cli can be installed with opam:

opam install elasticsearch-cli

Configuration file

The tool will look for a configuration file $XDG_HOME_CONFIG/es-cli/config.json when started ($XDG_HOME_CONFIG will be usually ~/.config; see XDG Base Directory Specification for more details).

An example configuration file:

  "clusters": {
    "cluster1": {
      "host": ""
    "cluster2": {
      "host": "",
      "nodes": [

With the above configuration file, it is possible to use alias names instead of full host names, for example:

es health cluster1 # show health for
es health # show health for all configured clusters
es search cluster2/myindex


Add or remove index alias

Add alias alias1 to myindex1 and alias alias2 to myindex2:

es alias -a myindex1 alias1 -a myindex2 alias2

Remove alias alias1 to myindex1 and alias alias2 to myindex2:

es alias -r myindex1 alias1 -r myindex2 alias2

Move index alias current from index-3 to index-4

es alias -r index-3 current -a index-4 current

Get document by id

es get

Check health of multiple clusters

es health

Check nodes of a cluster

Expect data0...data9, client0...client4 and master nodes to be present):

es nodes -h data{0..9} master client{0..4}

Expect all nodes listed for cluster mycluster in the elasticsearch-cli configuration to be present:

es nodes mycluster

Put document with or without id

es put '{ "first_name": "John", "last_name": "Doe" }'
es put '{ "first_name": "Jane", "last_name": "Doe" }'
echo '{ "first_name": "Johnny", "last_name": "Doe" }' | es put

Check shard recovery status

Display shards which are not in DONE stage:

es recovery -e stage done

Refresh indices

es refresh myindex1 myindex2

Query/search documents in an index

Search the index myindex for documents containing "Hello world!" in the title field. Return fields field1 and field2 of the document with the most recent value of the updated_at field:

es search myindex -i field1,field2 -s updated_at:desc -n 1 -q 'title:"Hello world!"'

Search the index myindex for documents containing 12345 in the field1 field. Return 10 documents' sources, omitting the boringfield field.

es search myindex -e boringfield -n 10 -f source '{"query":{"term":{"field1":12345}}}'

Show the number of documents in the index myindex with field field1 value greater or equal to 10:

es search myindex -n 0 -c -q 'field1:>=10'

Dependencies (9)

  1. atdgen >= "1.6.0"
  2. re2 >= "v0.9.0"
  3. lwt_ppx
  4. lwt >= "3.2.0"
  5. extlib >= "1.7.1"
  6. devkit >= "1.0"
  7. dune >= "1.5"
  8. mybuild build
  9. ocaml >= "4.01.0"

Dev Dependencies


Used by