繁体   English   中英

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

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

如何使用Rest Client在Elasticsearch中获取所有索引的列表?

(我在网上找到的所有答案似乎都与旧类型的客户有关。

我无法在文档中找到直接答案,

https://www.elastic.co/guide/zh-CN/elasticsearch/client/java-rest/current/index.html

无法找出要研究的部分,群集API或索引API等)

在当前的Java高级REST客户端中,您可以简单地通过请求带有“ *”作为索引名称的GetIndex请求来列出所有索引。

GetIndexRequest request = new GetIndexRequest().indices("*");
GetIndexResponse response = client.indices().get(request, RequestOptions.DEFAULT);
String[] indices = response.getIndices();

通过REST API,您可以使用以下URL进行验证: http:// elasticsearch:9200 / _cat / indices?v

通过Java Client API(我才意识到您是这样问的):您可以押注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();

您将获得索引列表;)

暂无
暂无

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

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