Reputation: 1
I need to fetch the count of indices available in ElasticSearch. Right now i am using /_cat/indices to fetch the list of indices and mapping it with array list and fetching the count. Is there any other API through which I can fetch the count of indices rather than fetching the list and counting it?
Thanks.
Upvotes: 0
Views: 7806
Reputation: 21
GET Call In POSTMAN -> http://address:9200/_cluster/stats
OR
curl --location --request GET 'http://address:9200/_cluster/stats'
===============================
Upvotes: 0
Reputation: 543
$ curl <elasticsearch-host-port>/_cluster/stats
And then look for indices.count in the response.
Upvotes: 3
Reputation: 217254
Since you're using the _cat/indices
API, you could simply return the results in JSON (instead of tabular form) and then pipe that into jq
in order to get the length of the index array you get in the response.
curl -s localhost:9200/_cat/indices?format=json | jq '. | length'
This will return a number equals to the number of indices you have.
Upvotes: 1