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

问题描述 投票:0回答:2

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

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

我没有在文档中找到直接答案,

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

无法确定要查看哪个部分,无论是Cluster还是Index API等。)

java elasticsearch
2个回答
2
投票

通过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();

你会得到指数列表;)


3
投票

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

GetIndexRequest request = new GetIndexRequest().indices("*");
GetIndexResponse response = client.indices().get(request, RequestOptions.DEFAULT);
String[] indices = response.getIndices();
© www.soinside.com 2019 - 2024. All rights reserved.