How do I get the list of all indices in Elasticsearch using the Rest Client?
(All answers I've found online seem to deal with the old type of client.
I fail to find the direct answer in the doc,
https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html
can't figure out which section to look into, either Cluster or Index APIs etc.)
In current Java High Level REST Client you can list all indices simply by requesting a GetIndex request with "*" as an index name.
GetIndexRequest request = new GetIndexRequest().indices("*");
GetIndexResponse response = client.indices().get(request, RequestOptions.DEFAULT);
String[] indices = response.getIndices();
Via the REST API you can verify with this URL : http://elasticsearch:9200/_cat/indices?v
Via the Java Client API (I just realised you asked this way) : you can bet on the Cluster Health API : https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-cluster-health.html
And use
ClusterHealthRequest request = new ClusterHealthRequest();
ClusterHealthResponse response = client.cluster().health(request, RequestOptions.DEFAULT);
Set<String> indices = response.getIndices().keySet();
And you will get the list of indices ;)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.