Saturday, 12 April 2014

Get list of indices in ElasticSearch through Java API

Being only briefly familiar with Elastic Search, I were tinkering ES Java API and googling for about an hour trying to get indices names.

Finally, decided to take a look into API sources and got my answer
ClusterStateRequestBuilder request = client.admin().cluster().prepareState();
request.clear().setMetaData(true); // fetch only cluster metadata
ClusterStateResponse state = request.execute().actionGet();
String[] indexes = state.getState().getMetaData().concreteAllIndices();
Wondering why this is not yet asked and answered on StackOverflow ;)

No comments :

Post a Comment