Find index of a document in elastic search using Alias

1k views Asked by At

I am using an alias to index my documents in the elastic search cluster.Basically indexes under this alias are created each month and any document ingested using this alias will reside in the index corresponding to the month in which it was ingested. The documents are indexed using Id and routing Id.

Now there is a use case where I have the Id and routing Id of the document and I need to find the exact index under the alias where this document resides. How can I find that out?

For example the document with Id A and routing Id B could be indexed in the index 11-2020(November index of 2020) and this index is under Alias AliasIndex.

Get operation using id and routingId wouldn't work because it requires the specific indexed to be passed.

I am using Java RestHighLevelClient.

1

There are 1 answers

2
Val On BEST ANSWER

You can always issue a search request by searching by id

GET alias-index/_search?routing=B
{
  "query": {
    "term": {
      "_id": "A"
    }
  }
}

In the response, you'll get the exact index of that document.