# AND + OR + Filter

**URL:** https://discuss.elastic.co/t/and-or-filter/10423
**Category:** Elasticsearch
**Created:** [January 20, 2013, 1:57am UTC](https://discuss.elastic.co/t/and-or-filter/10423 "2013-01-20T01:57:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![moocow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/moocow/32/2454_2.png) [@moocow](https://discuss.elastic.co/u/moocow)
#### Post date: [January 20, 2013, 1:57am UTC](https://discuss.elastic.co/t/and-or-filter/10423/1 "2013-01-20T01:57:47Z")

</div>

Hello,

is it possible to combine filter and query?

e.g.

filter -\> category:"Movies" and query\_string -\> query = ((horror AND movie)  
or (horror OR movie))

This will first filter to category Movies (fast) then perform the query on  
the results of the filter match.

Im using the following to do the query, If i can do the above, how can I  
add the filter part in?

curl -XGET '[http://localhost:9200/lists/list/\_search](http://localhost:9200/lists/list/_search)' -d '{  
"query":{  
"query\_string" : {  
"query" : "(user:lu) AND ((horror AND movie) OR (horror OR movie))",  
"analyzer":"stem"  
}  
}  
}'

Any help is very much appreciated  
Lu

--

---

<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 20, 2013, 3:27am UTC](https://discuss.elastic.co/t/and-or-filter/10423/2 "2013-01-20T03:27:47Z")

</div>

You can use a FilteredQuery...

{  
"query": {  
"filtered": {  
"query": {  
"query\_string": {  
"query": "(user:lu) AND ((horror AND movie) OR (horror  
OR movie))"  
}  
},  
"filter": {  
"terms": {  
"category": [  
"Movies"  
]  
}  
}  
}  
}  
}

On Saturday, January 19, 2013 8:57:47 PM UTC-5, moocow wrote:

> Hello,
> 
> is it possible to combine filter and query?
> 
> e.g.
> 
> filter -\> category:"Movies" and query\_string -\> query = ((horror AND  
> movie) or (horror OR movie))
> 
> This will first filter to category Movies (fast) then perform the query on  
> the results of the filter match.
> 
> Im using the following to do the query, If i can do the above, how can I  
> add the filter part in?
> 
> curl -XGET '[http://localhost:9200/lists/list/\_search](http://localhost:9200/lists/list/_search)' -d '{  
> "query":{  
> "query\_string" : {  
> "query" : "(user:lu) AND ((horror AND movie) OR (horror OR movie))",  
> "analyzer":"stem"  
> }  
> }  
> }'
> 
> Any help is very much appreciated  
> Lu

--

---

<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/and-or-filter/10423/3 "2017-07-06T02:55:31Z")

</div>


