Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 587
yousuf iqbal Avatar asked Mar 08 '23 19:03

yousuf iqbal


1 Answers

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"
            ]
          }
        }
      ]
    }
  }
}
like image 151
Val Avatar answered Mar 16 '23 21:03

Val