【问题标题】:Elasticsearch Java Rest Client: how to get the list of all indicesElasticsearch Java Rest Client:如何获取所有索引的列表
【发布时间】:2018-11-21 13:51:41
【问题描述】:

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

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

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

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

无法确定要查看哪个部分,集群或索引 API 等)

【问题讨论】:

标签: java elasticsearch


【解决方案1】:

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

通过 Java 客户端 API(我刚刚意识到您是这样问的):您可以押注集群健康 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();

你会得到索引列表;)

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2015-11-02
      • 1970-01-01
      • 2017-04-24
      • 2023-04-04
      • 2014-08-16
      • 2014-06-07
      • 2012-02-22
      • 1970-01-01
      • 2019-08-22
      相关资源
      最近更新 更多