Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if elasticsearch index is open or closed

Currently (v. 1.4.2) it is possible to check the existence of an index (although maybe not the ideally way), and to close and open an index. I don't see a way of checking if the index is opened or closed.

The status call returns an "IndexClosedException" which falls more in an exception handling case instead of informational one that I'm looking for.

How do you check this? Or is there another way to make a search without (possibly) passing an already closed index?

like image 244
tostasqb Avatar asked Jan 05 '15 12:01

tostasqb


2 Answers

Use GET /_cat/indices/my_index?v and you get something like this back:

health status index     pri rep docs.count docs.deleted store.size pri.store.size 
yellow open   my_index    5   1          2            0      5.3kb          5.3kb 

And you can see the status column.

like image 86
Andrei Stefan Avatar answered Sep 24 '22 15:09

Andrei Stefan


While the _cat endpoint is nice for humans, if you want something more script/program friendly you can do something like...

Lookup for a single index:

curl -GET 'http://es-host:9200/_cluster/state' | jq '.metadata.indices["index_name"].state'

List all indices:

curl -GET 'http://es-host:9200/_cluster/state' | jq '.metadata.indices | to_entries | .[] | {index: .key, state: .value.state}'
like image 27
Andrew White Avatar answered Sep 23 '22 15:09

Andrew White