6

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.

IQbrod
  • 2,060
  • 1
  • 6
  • 28
Chris
  • 1,092
  • 2
  • 19
  • 39

3 Answers3

4

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

  • 2
    A short example would have been nice, as there is not really a documentation besides the code. But I got it to work nevertheless so thanks for your time. – Chris Apr 28 '14 at 08:02
  • 1
    I've never used Jest and ran into the similar problem you were having. I figured if I gave the request you would be able to figure it out much quicker than I would :P. – Michael at qbox.io Apr 28 '14 at 15:28
  • Thats fair ;-). If it would be too easy it would be boring. – Chris Apr 29 '14 at 06:56
4

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.

Nathan
  • 8,093
  • 8
  • 50
  • 76
1

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"