有效地搜索 ID 的多个索引?

Search multiple indices for an ID efficiently?

我需要一份文件,但我不知道它在什么索引中。我有一堆不同日期的索引;全部以 "mydocs-" 为前缀。我试过:

GET /mydocs-*/adoc/my_second_doc

returns "index_not_found_exception"


GET /mydocs-*/adoc/_search
{
"query": {
  "bool":{
    "filter": [{
      "term":{
      "_id": ["my_second_doc"] 
    }
    }]
  }
  }
}

returns all the docs in the index.

现在,如果我搜索特定索引,我可以获得文档。问题是我并不总是事先知道它所在的索引。所以,我必须为它搜索很多很多索引(数以千计的索引)。

GET /mydocs-12/adoc/my_second_doc

returns 想要的文档。

关于如何为文档高效 Get/Search 有什么想法吗?

你试过吗:

GET mydocs-*/adoc/_search
{
  "query": {
        "term": {
            "_id": "my_second_doc"
        }
   }
}

或更具体地说:

GET mydocs-*/_search
{
  "query": {
    "bool": {
        "must": [
           {
               "term": {
                  "_id": "my_second_doc"
               }
           },
           {
               "term": {
                  "_type": "adoc"
               }
           }
        ]
    }
  }
}

以上两个查询会找到indexmydocs-开头,typeadocidmy_second_doc的所有文档].