# \[Filter Context\] terms query vs should query

**URL:** https://discuss.elastic.co/t/filter-context-terms-query-vs-should-query/177557
**Category:** Elasticsearch
**Created:** [April 19, 2019, 2:31am UTC](https://discuss.elastic.co/t/filter-context-terms-query-vs-should-query/177557 "2019-04-19T02:31:58Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![anirudh\_bharadwaj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anirudh_bharadwaj/32/44425_2.png) [@anirudh\_bharadwaj](https://discuss.elastic.co/u/anirudh_bharadwaj)
#### Post date: [April 19, 2019, 2:31am UTC](https://discuss.elastic.co/t/filter-context-terms-query-vs-should-query/177557/1 "2019-04-19T02:31:58Z")

</div>

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**

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

```

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

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

```

`boolquery-A OR boolquery-B` **represents**

```auto
"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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [May 17, 2019, 2:32am UTC](https://discuss.elastic.co/t/filter-context-terms-query-vs-should-query/177557/2 "2019-05-17T02:32:02Z")

</div>

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