Hi
I want to achive the following query in Python DSL
{
"query": {
"filtered":
{
"filter":
{
"and":
[
{ "terms": { "schoolID": 3456} },
{ "bool": {
"must": [
{ "term": { "facility": "1456" } },
{ "term": { "facility": "1457" } }
]
} },
{ "bool": {
"should": [
{ "range": {"fees": {"gte": min_fees, "lte": max_fees}} },
{"missing" : { "field" : "fees" }}
]
} },
{"geo_bounding_box":
{
"location":
{
"top_right":
{
"lat": X2,
"lon": y2
},
"bottom_left":
{
"lat": x1,
"lon": y1
}
}
}
}
]
}
}
}
}
What I have written in Python is
for facility in facilities:
facility_query.append({ "term": { "facility": int(facility) } })
s = Search(using=es, index="School", doc_type = "student")
.filter("term" , schoolID = schoolId )
.filter("geo_bounding_box", location = { "top_right" : {"lat": x2, "lon": y2 },
"bottom_left" : { "lat": x1, "lon": y1 }})
.query("range", fees = { "from": min_fees, "to": max_fees })
if facility:
s = s.query("bool", must= facility_query)
response = s.execute()
Two things I couldnt achieve
- In Price Range how to include missing field?
- Facility field I have to pass multiple values inside "must" bool query.
What needs to be altered in Python code to achieve it?