# List all indices using Java rest client

**URL:** https://discuss.elastic.co/t/list-all-indices-using-java-rest-client/317629
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [October 27, 2022, 4:05pm UTC](https://discuss.elastic.co/t/list-all-indices-using-java-rest-client/317629 "2022-10-27T16:05:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![PV2000](https://avatars.discourse-cdn.com/v4/letter/p/3d9bf3/32.png) [@PV2000](https://discuss.elastic.co/u/PV2000)
#### Post date: [October 27, 2022, 4:05pm UTC](https://discuss.elastic.co/t/list-all-indices-using-java-rest-client/317629/1 "2022-10-27T16:05:10Z")

</div>

Hi,

- What is the best way to get a list of all indices in Elastic Search using Java ? I am using RestHighLevelClient.
- Also, is there a way to get only those indices that match a prefix ?

I see cat indices REST endpoint provides the capability,  
[cat indices API | Elasticsearch Guide [7.17] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/cat-indices.html) , but I cant find any Java client example to invoke it.

---

<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: [October 27, 2022, 6:00pm UTC](https://discuss.elastic.co/t/list-all-indices-using-java-rest-client/317629/2 "2022-10-27T18:00:31Z")

</div>

> [@PV2000](#):
>
> What is the best way to get a list of all indices in Elastic Search using Java ? I am using RestHighLevelClient.

I dont know if best way but works:

```auto
    var response2 = getClient().indices().getMapping(new GetMappingsRequest().indices("*"),
        RequestOptions.DEFAULT);
    var indexes2 = response2.mappings().keySet()

```

> [@PV2000](#):
>
> Also, is there a way to get only those indices that match a prefix ?

Try this:

`new GetMappingsRequest().indices("idx_te*")`

---

<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: [November 24, 2022, 6:01pm UTC](https://discuss.elastic.co/t/list-all-indices-using-java-rest-client/317629/3 "2022-11-24T18:01:22Z")

</div>

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