Check if elasticsearch search index is open

Currently (version 1.4.2), you can check for the existence of an index (although perhaps not perfectly), and close and open the index . I see no way to check if the index is open or closed.

status returns an “IndexClosedException”, which is more relevant to the case of exception handling, and not to the informational one I'm looking for.

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

+7
elasticsearch
source share
4 answers

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

 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.

+5
source share

While the _cat endpoint is good for people, if you want something more user-friendly script / program, you can do something like ...

Single index search:

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

List of all indexes:

 curl -GET 'http://es-host:9200/_cluster/state' | jq '.metadata.indices | to_entries | .[] | {index: .key, state: .value.state}' 
+3
source share

The shortest way to get an open / closed response for a single index is to use the cat indexes API for the target index and restrict the returned column to only including status :

 curl http://localhost:9200/_cat/indices/some_index?h=status 

This should return either open or close . We use the same strategy for index health (red / yellow / green).

+2
source share

This is the answer to this question , which, I think, comes closer to what is expected.

Instead, you can use the cluster state API:

 GET _cluster/state/metadata/my_index 

or even:

 GET _cluster/state/metadata/my_index?filter_path=metadata.indices.*.state 
+2
source share

All Articles