# What is the difference between filtered query and regular query with filter?

**URL:** https://discuss.elastic.co/t/what-is-the-difference-between-filtered-query-and-regular-query-with-filter/413
**Category:** Elasticsearch
**Created:** [May 8, 2015, 5:57pm UTC](https://discuss.elastic.co/t/what-is-the-difference-between-filtered-query-and-regular-query-with-filter/413 "2015-05-08T17:57:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jsn](https://avatars.discourse-cdn.com/v4/letter/j/e56c9b/32.png) [@jsn](https://discuss.elastic.co/u/jsn)
#### Post date: [May 8, 2015, 5:57pm UTC](https://discuss.elastic.co/t/what-is-the-difference-between-filtered-query-and-regular-query-with-filter/413/1 "2015-05-08T17:57:23Z")

</div>

What is the different between these two queries?

{  
"query" : {  
"match" : {  
"field\_1" : true  
}  
},  
"filter" : {  
"and" :  
[  
{  
"exists" : {"field" : "field\_2"}  
},   
{  
"term" : {"field\_3" : "alien"}  
}  
]   
}  
}

{  
"query" : {  
"filtered" : {  
"query" : {  
"match" : {  
"field\_1" : true  
}  
},  
"filter" : {  
"and" :  
[  
{  
"exists" : {"field" : "field\_2"}  
},   
{  
"term" : {"field\_3" : "alien"}  
}  
]   
}  
}  
}  
}

is there a reason why one would choose the one against the other? I looked through the doc and can't find any thing explaining the differences.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [May 8, 2015, 7:59pm UTC](https://discuss.elastic.co/t/what-is-the-difference-between-filtered-query-and-regular-query-with-filter/413/2 "2015-05-08T19:59:58Z")

</div>

The difference is the execution mode, and agreed its confusing. This is why we changed the top level `filter` (as in, the same level as `query`) to [`post_filter`](http://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-post-filter.html).

Its all documented in the previous link, but in general, if you want everything to be filtered, you are better off using `filtered` query. If you want to only apply the filter on the hits, but not on aggregations, you should use `post_filter`. In your specific example, you should use `filtered` query.

---

<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, 12:14am UTC](https://discuss.elastic.co/t/what-is-the-difference-between-filtered-query-and-regular-query-with-filter/413/3 "2017-07-06T00:14:59Z")

</div>


