Get list of all indices using Elasticsearch Java API Client 7.17

I am using Elasticsearch Java API Client 7.17 to perform operations on my cluster. I can not find a way to get list of all indices in my cluster using this API.
I have found examples to achieve this using REST APIs but before using them I wanted to ensure is there a way to do this using Java API Client.
Thanks.

Hi @saurabhrs

Have you seen the documentation below? I believe it can help

API conventions | Elasticsearch Java API Client [7.17] | Elastic

Another API that can return all cluster indices is _cat/indices/all

best regards

Hi Gerson,

I went through the document that you shared. Thanks for that. However I couldn't find any example which solves my problem.
The other API that you mentiones (_cat/indices/all) is the REST API, but I am looking for the JAVA Client API to do the same.

Hi Saurabh.

Maybe you looking for:

    var restClient = RestClient.builder(new HttpHost("localhost", 9200)).build();
    var transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
    vzr client = new ElasticsearchClient(transport);
    var indices = client.indices().stats();

The IndicesStatsResponse return a map of indices.

Hi Andre,

Thanks for replying. But when I try to execute it I am getting an exception.

Exception Type: 'jakarta.json.stream.JsonParsingException' exception

Details:
com.fasterxml.jackson.core.exc.InputCoercionException: Numeric value (2409649519) out of range of int (-2147483648 - 2147483647)
at [Source: (org.apache.http.nio.entity.ContentInputStream); line: 1, column: 183]

Screen Shot:

It is getting thrown from Jackson and I am inble to figure out the reason. Do you have any clue on this.
Thanks

What version of es are you using?

Guided by this installation: Installation | Elasticsearch Java API Client [8.1] | Elastic

You can try this, but isnt elegant.

    var restClient = RestClient.builder(new HttpHost("localhost", 9200)).build();
    var request = new Request("GET", "_cat/indices");
    var results = restClient.performRequest(request);
    System.out.println(IOUtils.toString(results.getEntity().getContent(), StandardCharsets.UTF_8));

I am using 7.16.3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.