Search code examples
elasticsearch-7

ElasticSearch Python Client: how to get an index name behind an alias


I know how to get an alias if any given an index name in ElasticSearch:

es.indices.get_alias(indexname)

Is there a way to go the other way around? Something like es.indices.get_index(aliasname)? I implemented a workaround using the es.indices.get_alias for now but I am just curious.


Solution

  • I couldn't find any API returning an alias given an index name. Like I said, I had a workaround in Python using Elasticsearch module:

    def get_alias_behind_index(client, indexname):
        if client.indices.exists_alias(name=indexname):
            return (list(client.indices.get_alias(indexname).keys())[0])
        return None