elasticsearchsense

search multiple ids in multiple types in elasticsearch


I want to fetch documents with ids in specific type. For example right now I have wrote this query in Sense. This query is returning me all the documents with these ids in type product.

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

But what I want here is something like this

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

or

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

Is there any way to get it done?


Solution

  • You simply need to use the bool/filter query:

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