简体   繁体   English

使用别名在弹性搜索中查找文档的索引

[英]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.使用 Id 和路由 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.现在有一个用例,我有文档的 Id 和路由 Id,我需要在该文档所在的别名下找到确切的索引。 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 .例如,具有 Id A和路由 Id B的文档可以在索引11-2020 (2020 年 11 月索引)中进行索引,并且该索引在 Alias AliasIndex下。

Get operation using id and routingId wouldn't work because it requires the specific indexed to be passed.使用 id 和 routingId 获取操作不起作用,因为它需要传递特定的索引。

I am using Java RestHighLevelClient.我正在使用 Java RestHighLevelClient。

You can always issue a search request by searching by id您始终可以通过按 id 搜索来发出搜索请求

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

In the response, you'll get the exact index of that document.在响应中,您将获得该文档的确切索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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