# Get list of all indices using Elasticsearch Java API Client 7.17

**URL:** https://discuss.elastic.co/t/get-list-of-all-indices-using-elasticsearch-java-api-client-7-17/302395
**Category:** Elasticsearch
**Created:** [April 14, 2022, 6:58am UTC](https://discuss.elastic.co/t/get-list-of-all-indices-using-elasticsearch-java-api-client-7-17/302395 "2022-04-14T06:58:15Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![saurabhrs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saurabhrs/32/104382_2.png) [@saurabhrs](https://discuss.elastic.co/u/saurabhrs)
#### Post date: [April 14, 2022, 6:58am UTC](https://discuss.elastic.co/t/get-list-of-all-indices-using-elasticsearch-java-api-client-7-17/302395/1 "2022-04-14T06:58:15Z")

</div>

I am using [Elasticsearch Java API Client 7.17](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/7.17/index.html) 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.

---

<div class="post-metadata">

### Author: ![grfneto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grfneto/32/125776_2.png) [@grfneto](https://discuss.elastic.co/u/grfneto)
#### Post date: [April 14, 2022, 2:36pm UTC](https://discuss.elastic.co/t/get-list-of-all-indices-using-elasticsearch-java-api-client-7-17/302395/2 "2022-04-14T14:36:45Z")

</div>

Hi @saurabhrs

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

[API conventions | Elasticsearch Java API Client [7.17] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/7.17/api-conventions.html#_lists_and_maps)

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

> **[cat indices API | Elasticsearch Guide \[7.17\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/cat-indices.html#cat-indices-api-query-params)**

best regards

---

<div class="post-metadata">

### Author: ![saurabhrs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saurabhrs/32/104382_2.png) [@saurabhrs](https://discuss.elastic.co/u/saurabhrs)
#### Post date: [April 15, 2022, 6:14pm UTC](https://discuss.elastic.co/t/get-list-of-all-indices-using-elasticsearch-java-api-client-7-17/302395/3 "2022-04-15T18:14:06Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)
#### Post date: [April 16, 2022, 2:48am UTC](https://discuss.elastic.co/t/get-list-of-all-indices-using-elasticsearch-java-api-client-7-17/302395/4 "2022-04-16T02:48:44Z")

</div>

Hi Saurabh.

Maybe you looking for:

```auto
    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.

---

<div class="post-metadata">

### Author: ![saurabhrs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saurabhrs/32/104382_2.png) [@saurabhrs](https://discuss.elastic.co/u/saurabhrs)
#### Post date: [April 18, 2022, 7:22am UTC](https://discuss.elastic.co/t/get-list-of-all-indices-using-elasticsearch-java-api-client-7-17/302395/5 "2022-04-18T07:22:06Z")

</div>

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** :

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/c/bcb4651e5dd08d2e4112fc0e19f50e822a9f3b22.png)

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

---

<div class="post-metadata">

### Author: ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)
#### Post date: [April 18, 2022, 1:45pm UTC](https://discuss.elastic.co/t/get-list-of-all-indices-using-elasticsearch-java-api-client-7-17/302395/6 "2022-04-18T13:45:02Z")

</div>

What version of es are you using?

Guided by this installation: [Installation | Elasticsearch Java API Client [8.1] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/installation.html#maven)

You can try this, but isnt elegant.

```auto
    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));

```

---

<div class="post-metadata">

### Author: ![saurabhrs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saurabhrs/32/104382_2.png) [@saurabhrs](https://discuss.elastic.co/u/saurabhrs)
#### Post date: [April 18, 2022, 2:28pm UTC](https://discuss.elastic.co/t/get-list-of-all-indices-using-elasticsearch-java-api-client-7-17/302395/7 "2022-04-18T14:28:33Z")

</div>

I am using 7.16.3

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [May 16, 2022, 2:29pm UTC](https://discuss.elastic.co/t/get-list-of-all-indices-using-elasticsearch-java-api-client-7-17/302395/8 "2022-05-16T14:29:04Z")

</div>

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