# How to do \_cat/indices/\<index\_name\_with\_reg\_ex\> in JAVA

**URL:** https://discuss.elastic.co/t/how-to-do--cat-indices-index-name-with-reg-ex-in-java/79936
**Category:** Elasticsearch
**Created:** [March 24, 2017, 6:26pm UTC](https://discuss.elastic.co/t/how-to-do--cat-indices-index-name-with-reg-ex-in-java/79936 "2017-03-24T18:26:40Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![sholavanalli](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@sholavanalli](https://discuss.elastic.co/u/sholavanalli)
#### Post date: [March 24, 2017, 6:26pm UTC](https://discuss.elastic.co/t/how-to-do--cat-indices-index-name-with-reg-ex-in-java/79936/1 "2017-03-24T18:26:40Z")

</div>

I have some indexes with name test-1-in, test-2-in, test-3-in. I want to do \_cat/indices/test-\*-in from JAVA API. How to do this?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [March 24, 2017, 6:42pm UTC](https://discuss.elastic.co/t/how-to-do--cat-indices-index-name-with-reg-ex-in-java/79936/2 "2017-03-24T18:42:29Z")

</div>

You can't call cat API from transport client. It's a REST API only.

But you can look at the source code to see how it's implemented behind the scene and do the same thing from the transport client.

---

<div class="post-metadata">

### Author: ![sholavanalli](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@sholavanalli](https://discuss.elastic.co/u/sholavanalli)
#### Post date: [March 24, 2017, 7:59pm UTC](https://discuss.elastic.co/t/how-to-do--cat-indices-index-name-with-reg-ex-in-java/79936/3 "2017-03-24T19:59:10Z")

</div>

Thanks @dadoonet. I dug into \_cat implementation and found out what they are doing. Here it is:

```
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
clusterStateRequest.clear().metaData(true);
final IndicesOptions strictExpandIndicesOptions = IndicesOptions.strictExpand();
clusterStateRequest.indicesOptions(strictExpandIndicesOptions);
ClusterStateResponse clusterStateResponse = client.admin().cluster().state(clusterStateRequest).get(); 
clusterStateResponse.getState().getMetadata().getIndices() 

```

This will give all indexes. After that the reg ex matching has to be done manually.

---

<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: [April 21, 2017, 7:59pm UTC](https://discuss.elastic.co/t/how-to-do--cat-indices-index-name-with-reg-ex-in-java/79936/4 "2017-04-21T19:59:20Z")

</div>

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