Why elasticsearch does not come with a CLI?

Here is a nice CLI that you can build yourself. It is just one line:

alias escli='f(){ curl -X$1 "localhost:9200$2" -d "${@:3}" -H "Content-Type: application/json" -s -w "\n"; unset -f f; }; f'

Replace localhost:9200 with your elasticsearch address.

If you have JQ installed you can also pipe the output to it and get a nice colorized output.

alias escli='f(){ curl -X$1 "localhost:9200$2" -d "${@:3}" -H "Content-Type: application/json" -s | jq .; unset -f f; }; f'

Then you can call with:

$ escli GET /_search '{ "query": { "match_all": {} } }'
{
  "took": 5,
  "timed_out": false,
  "_shards": {
    "total": 0,
    "successful": 0,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": 0,
    "hits": []
  }
}

Works also with cat API (non-jq version):

$ escli GET /_cat/nodes?v
ip        heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
127.0.0.1           14          42   0    0.00    0.02     0.04 mdi       *      cLHz5qf
6 Likes