简体   繁体   中英

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:

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? It would also help if someone could show me a detailed documentation of 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.

http:// elasticsearch.company.com /_aliases

This will return an array of indexes and their aliases in JSON. Here's an example:

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

To get the list of indexes with Jest, use this code...

  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 .

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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