Reputation: 2074
Currently I am using elasticsearch in my rails application. My concern is how filter works in query is there any priority or ranking that this filter will apply first and other one in last OR it applied from top to bottom OR bottom to top :-
I have an example query with filter's below :-
{
"query": {
"constant_score": {
"filter": {
"bool": {
"must": [
{
"match_all": {
}
}
],
"filter": [
{
"term": {
"status": true
}
},
{
"geo_bounding_box": {
"location": {
"top_left": {
"lat": 40.8888,
"lon": -73.888888
},
"bottom_right": {
"lat": 41.8888,
"lon": -74.88888
}
}
}
},
{
"range": {
"get_booking_cut_off_time": {
"gte": 5.46
}
}
},
{
"terms": {
"show_to_list_val": [
"Both",
"Direct"
]
}
},
{
"range": {
"min_days": {
"lte": 1
}
}
},
{
"terms": {
"midoffice_master_id": [
10,
14
]
}
}
]
}
}
}
},
"_source": {
"includes": [
"name",
"code"
]
},
"size": 20,
"from": 0
}
So in above example I have term filter
, geo_bounding_box filter
and range filter
. I want to know that which filter should be apply first or last when query hits the elasticsearch api ??
Any help would be appreciable... :)
Upvotes: 1
Views: 997
Reputation: 2908
Take a look at this very detailed blog post from Elastic about the inner workings of query- and filter-execution:
https://www.elastic.co/de/blog/elasticsearch-query-execution-order
In the Conclusion-section at the end they state (quote):
Q: Does the order in which I put my queries/filters in the query DSL matter?
A: No, because they will be automatically reordered anyway based on their respective costs and match costs.
Hope this helps!
Upvotes: 3