简体   繁体   中英

Find index of a document in elastic search using Alias

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM