# Complicated filtered query

**URL:** <https://discuss.elastic.co/t/complicated-filtered-query/46089>\
**Category:** Elasticsearch\
**Created:** [April 1, 2016, 6:16pm UTC](https://discuss.elastic.co/t/complicated-filtered-query/46089 "2016-04-01T18:16:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gpong](https://avatars.discourse-cdn.com/v4/letter/g/d6d6ee/32.png) [@gpong](https://discuss.elastic.co/u/gpong)\
**Post date:** [April 1, 2016, 6:16pm UTC](https://discuss.elastic.co/t/complicated-filtered-query/46089/1 "2016-04-01T18:16:08Z")

</div>

Hi Guys,

I have some problem with filtered query.  
I need to add some filter like this  
in sql is like mtart in ('NLAG','ROH') AND werks in ('F230','F232') OR waers in ('RMB') AND zzcgrp in ('Venice')

so I used filtered query like this  
MUST (mtart:NLAG or mtart:ROH) AND (werks:F230 or werks:F232)  
MUST (waers:RMB) AND (zzcgrp:Venice)

and for query criteria, I used query\_string.  
So if if type mtart:HALB the result should be empty because I just want to show mtart=NLAG or mtart=ROH.

Can anyone help me?? Thanks

here is my query but when I tried to run this query. only one terms remaining. I don't know what the problem is??

{  
"query" : {  
"filtered" : {  
"filter" : {  
"bool" : {  
"must" : {  
"terms": {  
"mtart": [  
"roh",  
"nlag"  
]  
}  
},  
"must" : {  
"terms": {  
"werks": [  
"f230",  
"f232"  
]  
}  
},  
"must" : {  
"terms": {  
"waers": [  
"rmb"  
]  
}  
},  
"must" : {  
"terms": {  
"zzcgrp": [  
"venice"  
]  
}  
}  
}  
},  
"query": { "query\_string": {  
"query": "HALB"  
}}  
}  
}  
}

when I run the query will become

{  
"query": {  
"filtered": {  
"filter": {  
"bool": {  
"must": {  
"terms": {  
"zzcgrp": [  
"venice"  
]  
}  
}  
}  
},  
"query": {  
"query\_string": {  
"query": "HALB"  
}  
}  
}  
}  
}

---

<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, 11:03pm UTC](https://discuss.elastic.co/t/complicated-filtered-query/46089/2 "2017-07-05T23:03:09Z")

</div>

Closed on July 5, 2017, 11:03pm UTC


