package elasticsearch-cli

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


Dune Dependency






Published: 02 Oct 2020


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

Getting help

Show known commands

es --help

or just


Show man page for a command

es <command> --help

for example:

es search --help

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).

Cluster aliases

It is possible to use alias names instead of full host names.

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

show health for

es health cluster1

show health for all configured clusters

es health

search in

es search cluster2 myindex

find missing nodes in cluster2

es nodes cluster2

Note this command relies on the nodes parameter in the configuration file.

Command aliases

  "aliases": {
    "pause": {
      "command": "settings",
      "args": [ "-p", "cluster.routing.allocation.enable=none" ]
    "resume": {
      "command": "settings",
      "args": [ "-p", "cluster.routing.allocation.enable=all" ]

Pause shard allocation

es pause cluster1

Resume shard allocation

es resume cluster1

Search documents

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'

NOTE: ES 7.x and above will not return exact document count by default. Use -c -C true to print the exact value.

Count documents

Count documents containing "Hello world!" in the title field in the index myindex.

es count myindex -q 'title:"Hello world!"'

Add or remove index alias

Add alias alias1 to myindex1 and alias alias2 to myindex2:

es alias -a alias1=myindex1 -a alias2=myindex2

Remove alias alias1 from myindex1 and alias alias2 from myindex2:

es alias -r alias1=myindex1 -r alias2=myindex2

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

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

Remove alias alias1 and add alias alias2 to index.

es alias index -r alias1 -a alias2

Get document(s) by id

es get myindex docid


es get myindex docid1 docid2 docid3

Put document with or without id

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

Delete documents by id

es delete myindex docid1 docid2


es refresh myindex1 myindex2


es flush myindex1 myindex2

Use -f to force flush, -s to issue a synced flush, and -w to wait for an already ongoing flush.

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 configuration file to be present:

es nodes mycluster

Check shard recovery status

Display shards which are not in DONE stage:

es recovery -e stage done

Get or set cluster setttings

List all persistent and transient settings:

es settings

List all settings, including default ones:

es settings -D

Use -p, -t or -d to operate only on persistent, transient or default settings, respectively.

Update a persistent cluster setting:

es settings -p cluster.routing.allocation.enable=none

Dependencies (10)

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

Dev Dependencies


Used by





Innovation. Community. Security.