# How to OR-query on multiple different fields?

**URL:** <https://discuss.elastic.co/t/how-to-or-query-on-multiple-different-fields/10412>\
**Category:** Elasticsearch\
**Created:** [January 18, 2013, 7:10pm UTC](https://discuss.elastic.co/t/how-to-or-query-on-multiple-different-fields/10412 "2013-01-18T19:10:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ijonas\_Kisselbach](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ijonas_kisselbach/32/2521_2.png) [@Ijonas\_Kisselbach](https://discuss.elastic.co/u/Ijonas_Kisselbach)\
**Post date:** [January 18, 2013, 7:10pm UTC](https://discuss.elastic.co/t/how-to-or-query-on-multiple-different-fields/10412/1 "2013-01-18T19:10:22Z")

</div>

Hi,

I'm trying to perform the following pseudo query:

where fieldV=1 and fieldW=2 and (fieldX=3 or fieldY=4 or fieldZ=5)

I've got fieldV and fieldW working through

"query":{  
"bool":{  
"must":[  
{"query\_string":{"query":"fieldV:"1""}},  
{"query\_string":{"query":"fieldW:"2""}},  
]  
}  
},

but I don't know how to construct the OR-query.

I don't think I can use the OR-filter because I need the conditions to be  
included in the query so I can use facets on the result set.

Any help is sooooo appreciated.

Thanks,  
Ijonas.

--

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [January 18, 2013, 7:22pm UTC](https://discuss.elastic.co/t/how-to-or-query-on-multiple-different-fields/10412/2 "2013-01-18T19:22:34Z")

</div>

Hi Ijonas

> I don't think I can use the OR-filter because I need the conditions to  
> be included in the query so I can use facets on the result set.

Please could you send your example query with real field names and  
values. I ask because you probably CAN use filters for a number of  
fields (while still using facets). But it is difficult to know which  
ones to filter on without knowing what the fields mean

ta

clint

--

---

<div class="post-metadata">

**Author:** ![egaumer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/egaumer/32/2365_2.png) [@egaumer](https://discuss.elastic.co/u/egaumer)\
**Post date:** [January 18, 2013, 8:26pm UTC](https://discuss.elastic.co/t/how-to-or-query-on-multiple-different-fields/10412/3 "2013-01-18T20:26:56Z")

</div>

With query\_string, you can use Lucene syntax...

```
"query_string" : {
    "query" : "fieldV:1 AND fieldW:2 AND (fieldX:3 OR fieldY:4 OR 

```

fieldZ:5)"  
}

On Friday, January 18, 2013 2:10:22 PM UTC-5, Ijonas Kisselbach wrote:

> Hi,
> 
> I'm trying to perform the following pseudo query:
> 
> where fieldV=1 and fieldW=2 and (fieldX=3 or fieldY=4 or fieldZ=5)
> 
> I've got fieldV and fieldW working through
> 
> "query":{  
> "bool":{  
> "must":[  
> {"query\_string":{"query":"fieldV:"1""}},  
> {"query\_string":{"query":"fieldW:"2""}},  
> ]  
> }  
> },
> 
> but I don't know how to construct the OR-query.
> 
> I don't think I can use the OR-filter because I need the conditions to be  
> included in the query so I can use facets on the result set.
> 
> Any help is sooooo appreciated.
> 
> Thanks,  
> Ijonas.

--

---

<div class="post-metadata">

**Author:** ![Ijonas\_Kisselbach](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ijonas_kisselbach/32/2521_2.png) [@Ijonas\_Kisselbach](https://discuss.elastic.co/u/Ijonas_Kisselbach)\
**Post date:** [January 21, 2013, 2:26pm UTC](https://discuss.elastic.co/t/how-to-or-query-on-multiple-different-fields/10412/4 "2013-01-21T14:26:31Z")

</div>

Thanks both Clinton and egaumer!

I managed to solve this problem with the query+string + Lucene syntax  
suggested by egaumer. Dead simple.

--

---

<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:55am UTC](https://discuss.elastic.co/t/how-to-or-query-on-multiple-different-fields/10412/5 "2017-07-06T02:55:26Z")

</div>


