Get all indices associated with a given alias

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!

2 Likes

Hi,

Use:

GET indexname/_alias

Refer to the documentation here:

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

@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)

Try:

GET /_alias/esIndexAlias

1 Like

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

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

1 Like

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

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