# Get index by alias java api

**URL:** <https://discuss.elastic.co/t/get-index-by-alias-java-api/70438>\
**Category:** Elasticsearch\
**Created:** [January 3, 2017, 1:49pm UTC](https://discuss.elastic.co/t/get-index-by-alias-java-api/70438 "2017-01-03T13:49:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hrdxwandg](https://avatars.discourse-cdn.com/v4/letter/h/ad7895/32.png) [@hrdxwandg](https://discuss.elastic.co/u/hrdxwandg)\
**Post date:** [January 3, 2017, 1:49pm UTC](https://discuss.elastic.co/t/get-index-by-alias-java-api/70438/1 "2017-01-03T13:49:10Z")

</div>

how to get actual index name by index alias name with java api.  
the version of es is 2.4.0

for your help! thank you ahead!

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [January 3, 2017, 2:44pm UTC](https://discuss.elastic.co/t/get-index-by-alias-java-api/70438/2 "2017-01-03T14:44:42Z")

</div>

I had a quick look and couldn't see a specific API for this.  
You could always run a search with size 1 and the physical index name should be returned as part of matching documents' properties.

---

<div class="post-metadata">

**Author:** ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)\
**Post date:** [January 3, 2017, 2:47pm UTC](https://discuss.elastic.co/t/get-index-by-alias-java-api/70438/3 "2017-01-03T14:47:36Z")

</div>

My code is:

```
		// get name of the current index where the alias is active
		GetAliasesResponse r = client.admin().indices().getAliases(new GetAliasesRequest().aliases("YOUR_ALIAS")).get();

		for(Iterator<String> it = r.getAliases().keysIt(); it.hasNext();) {
			// HERE IS THE REALINDEXNAME
			String realIndexName = it.next();
		}
```

---

<div class="post-metadata">

**Author:** ![hrdxwandg](https://avatars.discourse-cdn.com/v4/letter/h/ad7895/32.png) [@hrdxwandg](https://discuss.elastic.co/u/hrdxwandg)\
**Post date:** [January 4, 2017, 2:26am UTC](https://discuss.elastic.co/t/get-index-by-alias-java-api/70438/4 "2017-01-04T02:26:59Z")

</div>

thanks for your reply.

you can check xavierfacq's answer. I test the code ,and it's OK

---

<div class="post-metadata">

**Author:** ![hrdxwandg](https://avatars.discourse-cdn.com/v4/letter/h/ad7895/32.png) [@hrdxwandg](https://discuss.elastic.co/u/hrdxwandg)\
**Post date:** [January 4, 2017, 2:27am UTC](https://discuss.elastic.co/t/get-index-by-alias-java-api/70438/5 "2017-01-04T02:27:17Z")

</div>

thank you very much. it's OK

---

<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:** [February 1, 2017, 2:27am UTC](https://discuss.elastic.co/t/get-index-by-alias-java-api/70438/6 "2017-02-01T02:27:56Z")

</div>

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