I have following elasticsearch query with terms-lookup-filter aggregation. Both queries will give the same result. Both queries have same filter type only the difference is order (place) of terms-lookup-filter.
1.Here terms-lookup filter is in 2nd/last position of and filter aggregation.
{
"size": 0,
"aggs": {
"filterAggs": {
"filter": {
"and": {
"filters": [
{
"range": {
"eligibleDates": {
"include_lower": true,
"include_upper": true,
"from": <fromDate>,
"to": <toDate>
}
}
},
{
"terms": {
"rollNo": {
"path": "student.rollNo",
"index": "<index_name>",
"id": "<record_id>",
"type": "<es Type>"
}
}
}
]
}
}
}
}
}
2.Here terms-lookup filter is in 1st position of and filter aggregation.
{
"size": 0,
"aggs": {
"filterAggs": {
"filter": {
"and": {
"filters": [
{
"terms": {
"rollNo": {
"path": "student.rollNo",
"index": "<index_name>",
"id": "<record_id>",
"type": "<es Type>"
}
}
},
{
"range": {
"eligibleDates": {
"include_lower": true,
"include_upper": true,
"from": <fromDate>,
"to": <toDate>
}
}
}
]
}
}
}
}
}
In my experiment/test, 1st query executes more efficiently (7 to 10 times faster) than the second one. Now my question is, Does terms-lookup-filter aggregation order in elasticsearch query affect the execution time (efficiency)? How will the filter place order affect execution time?