Why elasticsearch does not come with a CLI?

It has been 2-3 months I have been using elasticsearch. I often wonder why we elasticsearch has its own CLI ?

Almost all other databases have a shell.

I am not looking for a CLI. I just want to know why ? Is it not possible ? If not possible, then why ?

Because tools like curl exist on the (linux) shell.
If you want more, then look at Console (which is part of Kibana), or Postman or similar.

1 Like

One of the aspects that I really like about ES is its REST interface. And since using REST via cURL or HTTPie is so simple, that if you were to wrap it around with a CLI, in my very humble opinion, you would not gain much.

If you haven't already, give cURL or HTTPie a go. :slight_smile:

2 Likes

I think there is quite a lot to be gained. MongoDB has a hybrid CLI w/ JSON
interface. Having a result set as a cursor to iterate through facilitates
development. Having host/index/type defined as a local variable cuts down
on the complexity of using curl.

But is a CLI worthwhile? Debatable. Although I would like to use one, I
would not have it as a priority.

1 Like

@Ivan @warkolm @mujtabahussain

Thank you for the answer.

Actually I was doing some sort of research on elastic and influxdb. And there I thought why elastic does not provide a CLI but influx does.

Whenever you find time to explain, Can you give me some or any of those debatable points which were considered while not providing a CLI ? That would be really helpful.

I do not think that a CLI was not created because there was a decision not
to create one. There is no CLI because there never was one built. How would
an answer change your usage of a product?

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

That's super cool thing @thiago!

2 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.