How to get a List of Indices from ElasticSearch using Jest

Get Aliases will give you all the aliases for the indices on a node.


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.