0

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.

2
  • 1
    I think terms query is exactly what you need. Why do you think it will not work for you? I am not sure I understand what you mean by "distinct from_user_id field". Commented Nov 1, 2012 at 13:45
  • I tried doing {"size":2,"query":{"terms":{"from_user_id": ["86746184549","333621309995644"]}}}, but this gave me 2 results containing the same from_user_id` value -> "86746184549". How do I fetch 2 records that contain the 2 distinct from_user_id values. I don't want to query the entire data set that's the reason why I have specified size in the request body. Just want to fetch 2 records one containing "86746184549" and the other "333621309995644" in the from_user_id field. ` Commented Nov 1, 2012 at 14:15

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

looking forward to this new feature!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.