0

I have a list, id_list = [1, 3, 5, 7]

I need to fetch data from elasticsearch corresponding to the ids present in id_list, similar to id__in that we do for postgres.

I was trying to find a way using elasticsearch_dsl.Search(), but I am stuck at it. Any help with the code or relevant documentation will be very helpful.

1 Answer 1

1

You can use terms query to perform "in" query in elasticsearch

Try out the below query

{
  "query": {
    "terms": {
      "id_list": [
        1,
        3,
        5,
        7
      ]
    }
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer. Adding on to your point, for python we can use something like this s.query(query).filter('terms', id=[1, 3, 5, 7])
@uglyCoder yes you can include filter clause as well if you are not concerned about the scoring part, and you just want to know whether the id matched or not

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.