Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch find all indexes using the Java client

Is there a way to use the Java client to get a list of indexes that are in Elasticsearch? I have been able to find examples of doing this using Marvel/Sense, but I cant seem to find any examples of doing this using the Java client.

like image 559
Mike Rylander Avatar asked Oct 14 '15 20:10

Mike Rylander


People also ask

How do I search all indexes in Elasticsearch?

To search multiple data streams and indices, add them as comma-separated values in the search API's request path. The following request searches the my-index-000001 and my-index-000002 indices. You can also search multiple data streams and indices using an index pattern.

How do I get a list of indexes in Kibana?

Open Kibana's main menu and click Stack Management > Index Management. The Index Management page contains an overview of your indices. Badges indicate if an index is a follower index, a rollup index, or frozen. Clicking a badge narrows the list to only indices of that type.

What is an IndexRequest?

IndexRequest defines the document to add to ElasticSearch, as opposed to UpdateRequest which actually performs the addition into ElasticSearch. Note: UpdateRequest. upsert() expects a separate IndexRequest to be used just if the document does not exist.

Where are Elasticsearch indexes stored?

Indexes are stored in Elasticsearch as inverted indexes. Indexes are stored in Elasticsearch as inverted indexes. This means that each index contains a list of all the terms that appear in the documents that are stored in that index.


2 Answers

Another way I found to do this:

client.admin()
    .indices()
    .getIndex(new GetIndexRequest())
    .actionGet()
    .getIndices()
like image 89
Mike Rylander Avatar answered Oct 23 '22 10:10

Mike Rylander


It's definitely possible but it's unfortunately not documented in the official documentation for the Java client. You can achieve this with:

List<IndexMetaData> indices = client.admin().cluster()
    .prepareState().get().getState()
    .getMetaData().getIndices();
like image 40
Val Avatar answered Oct 23 '22 08:10

Val