简体   繁体   English

Elasticsearch Java Rest Client:如何获取所有索引的列表

[英]Elasticsearch Java Rest Client: how to get the list of all indices

How do I get the list of all indices in Elasticsearch using the Rest Client? 如何使用Rest Client在Elasticsearch中获取所有索引的列表?

(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 https://www.elastic.co/guide/zh-CN/elasticsearch/client/java-rest/current/index.html

can't figure out which section to look into, either Cluster or Index APIs etc.) 无法找出要研究的部分,群集API或索引API等)

In current Java High Level REST Client you can list all indices simply by requesting a GetIndex request with "*" as an index name. 在当前的Java高级REST客户端中,您可以简单地通过请求带有“ *”作为索引名称的GetIndex请求来列出所有索引。

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 通过REST API,您可以使用以下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 通过Java Client API(我才意识到您是这样问的):您可以押注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 ;) 您将获得索引列表;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM