es_user
es_user

Reputation: 1

Count of indices in elasticsearch

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

Answers (3)

Bilal Hayat
Bilal Hayat

Reputation: 21

GET Call In POSTMAN -> http://address:9200/_cluster/stats OR

curl --location --request GET 'http://address:9200/_cluster/stats'

===============================

enter image description here

Upvotes: 0

yty
yty

Reputation: 543

$ curl <elasticsearch-host-port>/_cluster/stats

And then look for indices.count in the response.

Upvotes: 3

Val
Val

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

Related Questions