简体   繁体   English

如何使用 Jest 从 ElasticSearch 获取索引列表

[英]How to get a List of Indices from ElasticSearch using Jest

I'm trying to retrieve a list of indices using Jest, but I just got as far as:我正在尝试使用 Jest 检索索引列表,但我只是:

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

How can i retrieve the list of indices from the result?如何从结果中检索索引列表? Do I have to use something else than Stats?我必须使用 Stats 以外的其他东西吗? It would also help if someone could show me a detailed documentation of Jest.如果有人可以向我展示 Jest 的详细文档,这也会有所帮助。 The basics are really well documented, but with the different kinds of builders I'm really lost at the moment.基础知识确实有据可查,但是对于不同类型的构建器,我现在真的很迷茫。

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

One can simply navigate a browser to the following URL to get the indexes available on an ElasticSearch cluster.只需将浏览器导航到以下 URL,即可获取 ElasticSearch 集群上可用的索引。

http:// elasticsearch.company.com /_aliases HTTP:// elasticsearch.company.com / _aliases

This will return an array of indexes and their aliases in JSON.这将在 JSON 中返回一组索引及其别名。 Here's an example:下面是一个例子:

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

To get the list of indexes with Jest, use this code...要使用 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();

Use your favorite JSON processor to extract the indexes from json .使用您最喜欢的 JSON 处理器从json提取索引。

Use:用:

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

This will return a JSON response just like curl -XGET "localhost:9200/_cat/indices?format=json"这将返回一个 JSON 响应,就像curl -XGET "localhost:9200/_cat/indices?format=json"

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

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