如何使用Rest Client在Elasticsearch中获取所有索引的列表?
(我在网上找到的所有答案似乎都与旧类型的客户有关。
我无法在文档中找到直接答案,
https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html
无法确定要研究哪个部分,集群API或索引API等。
答案 0 :(得分:2)
通过您可以使用以下URL验证的REST API:http://elasticsearch:9200/_cat/indices?v
通过Java客户端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();
您将获得索引列表;)
答案 1 :(得分:1)
在当前的Java高级REST客户端中,您可以简单地通过请求带有“ *”作为索引名称的GetIndex request来列出所有索引。
GetIndexRequest request = new GetIndexRequest().indices("*");
GetIndexResponse response = client.indices().get(request, RequestOptions.DEFAULT);
String[] indices = response.getIndices();