Elasticsearch Java Rest Client:如何获取所有索引的列表 [英] Elasticsearch Java Rest Client: how to get the list of all indices
问题描述
如何使用Rest Client在Elasticsearch中获取所有索引的列表?
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/zh-CN/elasticsearch/client/java-rest/current/index.html
无法确定要查找哪个部分,无论是集群API还是索引API等.
can't figure out which section to look into, either Cluster or Index APIs etc.)
推荐答案
Via the REST API you can verify with this URL : http://elasticsearch:9200/_cat/indices?v
通过Java Client API(我才刚刚意识到您是这样问的):您可以押注Cluster Health API:
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
并使用
ClusterHealthRequest request = new ClusterHealthRequest();
ClusterHealthResponse response = client.cluster().health(request, RequestOptions.DEFAULT);
Set<String> indices = response.getIndices().keySet();
您将获得索引列表;)
这篇关于Elasticsearch Java Rest Client:如何获取所有索引的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!