在elasticsearch中搜索多种类型的多个id

search multiple ids in multiple types in elasticsearch

我想获取具有特定类型 ID 的文档。例如,现在我已经在 Sense 中编写了这个查询。此查询返回所有具有这些 ID 的产品类型的文档。

  POST /_search
    {
        "query": {
           "ids" :{
              "type" : "product",
              "values" : ["100005","10002010093"]
         }
      }
    }

但我想要的是这样的

 POST /_search
        {
            "query": [
             {
               "ids" :{
                  "type" : "product",
                  "values" : ["100005","10002010093"]
             }
             },
             {
               "ids" :{
                  "type" : "store",
                  "values" : ["100003","1000201"]
             }
             }
         ]
        }

 POST /_search
        {
            "query":{
                "ids" :[
                  {
                     "type" : "product",
                     "values" : ["100005","10002010093"]
                  },
                  {
                     "type" : "store",
                     "values" : ["100003","1000201"]
                  }
               ]
            }
        }

有什么办法可以做到吗?

您只需使用 bool/filter query:

POST /_search
{
  "query": {
    "bool": {
      "should": [
        {
          "ids": {
            "type": "product",
            "values": [
              "100005",
              "10002010093"
            ]
          }
        },
        {
          "ids": {
            "type": "store",
            "values": [
              "100003",
              "1000201"
            ]
          }
        }
      ]
    }
  }
}