0

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.

Kunal gupta
  • 481
  • 2
  • 7
  • 19

1 Answers1

1

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.

Val
  • 207,596
  • 13
  • 358
  • 360
  • what would be corresponding JavaRestClient implementation ?? Also Kunal if you are able to write it can you please share it? – Psycho Jun 19 '21 at 21:36
  • Hi @Psycho, Sorry I just saw this comment today. Here is the code that I wrote- QueryBuilder query = QueryBuilders.idsQuery().addIds(**idOfDocument*); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query(query); return new SearchRequest() .indices(**alias**) .routing(**routingKey*) .source(searchSourceBuilder); Then i just called resthighlevel client's search method and got the index using this - searchResponse.getHits().getAt(0).getIndex() Hope that helps. – Kunal gupta Aug 25 '21 at 16:06