[Filter Context] terms query vs should query

(Anirudh Bharadwaj) #1

I want to know the difference in query performance of a terms query vs a should query in filter context.
i.e,


Approach 1

Result =
(myField in ['A1', 'A2'] AND condition-1)
OR
(myField in ['B1', 'B2'] AND condition-2)

Approach 2

Result =
(myField ='A1' AND condition-1)
OR
(myField ='A2' AND condition-1)
OR
(myField ='B1' AND condition-2)
OR
(myField ='B2' AND condition-2)


myField is a keyword
condition-N is a bool query

(myField ='A1' **AND** condition-1) represents

"bool" : { "filter" : [ {"term" : {"myField" : "A1"}},{condition-1 } ]}

(myField in ['A1', 'A2'] **AND** condition-1) represents

"bool" : { "filter" : [ {"terms" : {"myField" : ["A1", "A2"]}},{condition-1 } ]}

boolquery-A OR boolquery-B represents

"should" : [ {boolquery-A},{boolquery-B}]

and has "minimum_should_match" : "1"


I want to know if the query optimizer would plan both approaches in the same way. If not, which approach would be more efficient in terms of query performance.

I tested both approaches and did not find much difference in performance.

(system) closed #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.