问题
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.)
回答1:
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 ;)
回答2:
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();
来源:https://stackoverflow.com/questions/53413584/elasticsearch-java-rest-client-how-to-get-the-list-of-all-indices