# Get all indices associated with a given alias

**URL:** https://discuss.elastic.co/t/get-all-indices-associated-with-a-given-alias/74944
**Category:** Elasticsearch
**Created:** [February 14, 2017, 12:01am UTC](https://discuss.elastic.co/t/get-all-indices-associated-with-a-given-alias/74944 "2017-02-14T00:01:18Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![animageofmine](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@animageofmine](https://discuss.elastic.co/u/animageofmine)
#### Post date: [February 14, 2017, 12:01am UTC](https://discuss.elastic.co/t/get-all-indices-associated-with-a-given-alias/74944/1 "2017-02-14T00:01:18Z")

</div>

I know there is a way to get all the aliases associated with given index, but is there a way to get all the indices for a given alias?

Input: Alias  
Output: List[Index]

The only approach I know of is to get aliases and iterate through each one of them, but it can be expensive if we have too many indices/aliases in production. Please let me know. Thank you.

Would like to know ES API and Java/Scala API. I am using Elastic4s client, BTW.

Thank you!

---

<div class="post-metadata">

### Author: ![msimos](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@msimos](https://discuss.elastic.co/u/msimos)
#### Post date: [February 14, 2017, 12:06am UTC](https://discuss.elastic.co/t/get-all-indices-associated-with-a-given-alias/74944/2 "2017-02-14T00:06:52Z")

</div>

Hi,

Use:

GET indexname/\_alias

Refer to the documentation here:

[https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html#alias-retrieving](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html#alias-retrieving)

---

<div class="post-metadata">

### Author: ![animageofmine](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@animageofmine](https://discuss.elastic.co/u/animageofmine)
#### Post date: [February 14, 2017, 12:13am UTC](https://discuss.elastic.co/t/get-all-indices-associated-with-a-given-alias/74944/3 "2017-02-14T00:13:50Z")

</div>

@msimos I looked at the document and didn't find the answer (unless I overlooked something). Your answer gives me alias, given an index name. My request is opposite to your answer. Following is what I am expecting

Input: AliasName  
Output: List of Indices associated with that Alias

Example:  
Index: esIndex1, esIndex2  
Alias: esIndexAlias

```
POST /_aliases
{
    "actions" : [
        { "add" : { "index" : "esIndex1", "alias" : "esIndexAlias" } },
        { "add" : { "index" : "esIndex2", "alias" : "esIndexAlias" } }
    ]
}

```

Now, I want to get both the indices (esIndex1 and esIndex2) for a given alias (esIndexAlias)

---

<div class="post-metadata">

### Author: ![msimos](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@msimos](https://discuss.elastic.co/u/msimos)
#### Post date: [February 14, 2017, 12:29am UTC](https://discuss.elastic.co/t/get-all-indices-associated-with-a-given-alias/74944/4 "2017-02-14T00:29:41Z")

</div>

Try:

GET /\_alias/esIndexAlias

---

<div class="post-metadata">

### Author: ![animageofmine](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@animageofmine](https://discuss.elastic.co/u/animageofmine)
#### Post date: [February 14, 2017, 12:40am UTC](https://discuss.elastic.co/t/get-all-indices-associated-with-a-given-alias/74944/5 "2017-02-14T00:40:09Z")

</div>

@msimos cool, that should work. Any idea about associated Java API? If you know about elastic4s, its a bonus 🙂

---

<div class="post-metadata">

### Author: ![msimos](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@msimos](https://discuss.elastic.co/u/msimos)
#### Post date: [February 14, 2017, 1:11am UTC](https://discuss.elastic.co/t/get-all-indices-associated-with-a-given-alias/74944/6 "2017-02-14T01:11:14Z")

</div>

Take a look at this link it should give you some ideas:

> <https://stackoverflow.com/questions/25349947/how-to-find-index-by-alias-in-elasticsearch-java-api>

---

<div class="post-metadata">

### Author: ![animageofmine](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@animageofmine](https://discuss.elastic.co/u/animageofmine)
#### Post date: [March 3, 2017, 9:05pm UTC](https://discuss.elastic.co/t/get-all-indices-associated-with-a-given-alias/74944/7 "2017-03-03T21:05:14Z")

</div>

Sorry, I forgot to post, but that worked! Thank you again.

---

<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: [March 31, 2017, 9:05pm UTC](https://discuss.elastic.co/t/get-all-indices-associated-with-a-given-alias/74944/8 "2017-03-31T21:05:23Z")

</div>

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