Reputation: 825
In my elasticsearch I want to get all the indices' name of the cluster. How can I do using java? I search the internet but there's no much useful information.
Upvotes: 1
Views: 3716
Reputation: 11
You can use:
client.admin().indices().prepareGetIndex().setFeatures().get().getIndices();
Use setFeatures()
without parameter to just get index name. Otherwise, other data, such as MAPPINGS
and SETTINGS
of index, will also be returned by default.
Upvotes: 1
Reputation: 825
Thanks for @Val's answer. According to your method, I use it in my projects, the code is:
ClusterStateResponse response = transportClient.admin().cluster() .prepareState()
.execute().actionGet();
String[] indices=response.getState().getMetaData().getConcreteAllIndices();
This method can put all the indices name into a String array. The method works.
there's another method I think but not tried:
ImmutableOpenMap<String, MappingMetaData> mappings = node.client().admin().cluster()
.prepareState().execute().actionGet().getState().getMetaData().getIndices().
then, we can get the keys of mappings to get all the indices. Thanks again!
Upvotes: 0
Reputation: 217274
You can definitely do it with the following simple Java code:
List<IndexMetaData> indices = client.admin().cluster()
.prepareState().get().getState()
.getMetaData().getIndices();
The list you obtain contains the details on all the indices available in your ES cluster.
Upvotes: 1