mansk
mansk

Reputation: 101

Combine separate queries in elasticsearch

I have two search terms "86746184549" and "3302093809". I am executing two separate term queries to fetch one document matching each of the ids.

"size":1,
"query":{
  "term":{
    "from_user_id": "86746184549"
  }

}

and

"size":1,
"query":{
  "term":{
    "from_user_id": "3302093809"
  }

}

Is there are a way to combine these 2 queries, something similar to what we do in facets.

 {
    "facets":{
      "facet_1":{

       },
      "facet_2":{

       },
      "facet_3":{

       }  
    }
 }

I don't think the terms query will work here because, that wont return documents containing distinct from_user_id field.

The reason I want to combine the queries is because, say if I have 100 such terms then I will be making 100 calls!! to the elasticsearch server.

Upvotes: 0

Views: 4108

Answers (1)

imotov
imotov

Reputation: 30163

It sounds like you are looking for Field Collapsing/Combining, which is highly sought-after feature of elasticsearch that's not implemented yet. Meanwhile, you can use Multi Search to combine several term requests into one.

Upvotes: 2

Related Questions