Reputation: 3608
I have written following Query for Elasticsearch which works as expected
es = self.get_elastic_search_instance()
s = Search(using=es, index="school", doc_type = "student") \
.filter("term" , studentId = student_ID ) \
.filter("term" , isPremium = premium_search ) \
.filter("geo_bounding_box", location = { "top_right" : {"lat": x2, "lon": y2 },
"bottom_left" : { "lat": x1, "lon": y1 }}) \
.query("range", termFees = { "from": min_fee, "to": max_fee })
if course_query:
s = s.filter ("terms" ,courseId = [1302 , 1303 ] )
I would like to add two constraints
How to include them, I tried with few options it didnt work.
Upvotes: 0
Views: 207
Reputation: 12672
You need to write multiple should filters
like this, |
is OR(should) operator
from elasticsearch_dsl import Search, Q, F <--- Import F(for Filters)
s = s.filter(F('terms', courseId = [1302 , 1303 ]) |
F('missing', field='courseId') |
F('missing' , field='termFees'))
print s.to_dict() <--- it will print JSON query, very helpful
Hope this helps!!
Upvotes: 1