# Query string logic

**URL:** <https://discuss.elastic.co/t/query-string-logic/51091>\
**Category:** Elasticsearch\
**Created:** [May 26, 2016, 7:13pm UTC](https://discuss.elastic.co/t/query-string-logic/51091 "2016-05-26T19:13:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick\_Lam](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@Patrick\_Lam](https://discuss.elastic.co/u/Patrick_Lam)\
**Post date:** [May 26, 2016, 7:13pm UTC](https://discuss.elastic.co/t/query-string-logic/51091/1 "2016-05-26T19:13:20Z")

</div>

Hi,

I'm having a little trouble understanding a specific Boolean logic from a query string query I'm running.

Suppose we have words a, b, and c. I get the following document counts with each query.

a: 948  
b: 105  
a OR b: 971  
b AND NOT c: 104  
a AND NOT c: 947  
a OR (b AND NOT c): 971  
a OR b AND NOT c: 104

So I don't understand the last one. Why is it that when I take out the parentheses around (b AND NOT c), it doesn't seem to recognize the a term at all.

Put another way, "b AND NOT c" gives me the same result as "a OR b AND NOT c" even though a is by far the most popular term and "a AND NOT c" still gives me 947 docs. I would have expected "a OR b AND NOT c" to be equivalent to "a OR (b AND NOT c)".

---

<div class="post-metadata">

**Author:** ![Patrick\_Lam](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@Patrick\_Lam](https://discuss.elastic.co/u/Patrick_Lam)\
**Post date:** [May 26, 2016, 7:39pm UTC](https://discuss.elastic.co/t/query-string-logic/51091/2 "2016-05-26T19:39:03Z")

</div>

Never mind. I think I figured it out. The presence of AND is making b a required term without parentheses.

---

<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:** [July 5, 2017, 10:48pm UTC](https://discuss.elastic.co/t/query-string-logic/51091/3 "2017-07-05T22:48:46Z")

</div>


