如何使用Jest从ElasticSearch获取指数列表

问题描述 投票:6回答:3

我正在尝试使用Jest检索索引列表,但我只是得到:

        Stats statistics = new Stats.Builder().build();
        result = client.execute(statistics);

如何从结果中检索索引列表?我是否必须使用除Stats之外的其他内容?如果有人可以向我展示Jest的详细文档,这也会有所帮助。基础知识确实很好,但是对于不同类型的构建者,我现在真的迷失了。

java elasticsearch jest
3个回答
4
投票

Get Aliases将为您提供节点上索引的所有别名。


3
投票

可以简单地将浏览器导航到以下URL以获取ElasticSearch集群上的索引。

HTTP://elastic search.company.com/_aliases

这将返回JSON中的索引及其别名数组。这是一个例子:

{
    "compute-devzone1": { },
    "compute-den2": { },
    "compute-den1": { },
    ...
}

要使用Jest获取索引列表,请使用此代码...

  HttpClientConfig config;
  JestClientFactory factory;
  JestClient client;
  GetAliases aliases;
  JestResult result;
  String json;

  config = new HttpClientConfig.
     Builder("http://elasticsearch.company.com").
     build();

  aliases = new GetAliases.
     Builder().
     build();

  factory = new JestClientFactory();

  factory.setHttpClientConfig(config);

  client = factory.getObject();
  result = client.execute(aliases);
  json   = result.getJsonString();

使用您最喜欢的JSON处理器从json中提取索引。


1
投票

使用:

JestResult result = elasticSearchClient.execute(new Cat.IndicesBuilder().build());

这将返回一个JSON响应,就像curl -XGET "localhost:9200/_cat/indices?format=json"一样

© www.soinside.com 2019 - 2024. All rights reserved.