# Use "AND" and "OR" operator in one query

**URL:** <https://discuss.elastic.co/t/use-and-and-or-operator-in-one-query/10064>\
**Category:** Elasticsearch\
**Created:** [December 13, 2012, 1:45pm UTC](https://discuss.elastic.co/t/use-and-and-or-operator-in-one-query/10064 "2012-12-13T13:45:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Boaz\_Trindade](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Boaz\_Trindade](https://discuss.elastic.co/u/Boaz_Trindade)\
**Post date:** [December 13, 2012, 1:45pm UTC](https://discuss.elastic.co/t/use-and-and-or-operator-in-one-query/10064/1 "2012-12-13T13:45:28Z")

</div>

Hi,

I need to do two kind of searches in one search , using "AND" and "OR"  
operator. The sort result should be with "AND" before "OR" operator.

Is it possible?

Tks.

--

---

<div class="post-metadata">

**Author:** ![Raffaele\_Sena](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raffaele_sena/32/1759_2.png) [@Raffaele\_Sena](https://discuss.elastic.co/u/Raffaele_Sena)\
**Post date:** [December 13, 2012, 9:03pm UTC](https://discuss.elastic.co/t/use-and-and-or-operator-in-one-query/10064/2 "2012-12-13T21:03:06Z")

</div>

Lucene doesn't apply any precedence to AND/OR operators so you need to wrap  
your conditionals in parenthesis :

test:(some AND stuff) OR (some AND other)

On Thu, Dec 13, 2012 at 5:45 AM, Boaz Trindade [boaz.trindade@gmail.com](mailto:boaz.trindade@gmail.com)wrote:

> Hi,
> 
> I need to do two kind of searches in one search , using "AND" and "OR"  
> operator. The sort result should be with "AND" before "OR" operator.
> 
> Is it possible?
> 
> Tks.
> 
> --

--

---

<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 6, 2017, 2:59am UTC](https://discuss.elastic.co/t/use-and-and-or-operator-in-one-query/10064/3 "2017-07-06T02:59:53Z")

</div>


