# What are the differences between "filter" and "filtered"?

**URL:** <https://discuss.elastic.co/t/what-are-the-differences-between-filter-and-filtered/8239>\
**Category:** Elasticsearch\
**Created:** [June 27, 2012, 8:50am UTC](https://discuss.elastic.co/t/what-are-the-differences-between-filter-and-filtered/8239 "2012-06-27T08:50:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ngocvo3103](https://avatars.discourse-cdn.com/v4/letter/n/aca169/32.png) [@ngocvo3103](https://discuss.elastic.co/u/ngocvo3103)\
**Post date:** [June 27, 2012, 8:50am UTC](https://discuss.elastic.co/t/what-are-the-differences-between-filter-and-filtered/8239/1 "2012-06-27T08:50:27Z")

</div>

Hi all,

I'm a newbie in Elastic Search. I got a question subject while researching  
ES "What are the differences between "filter" and "filtered" ?  
I tried creating 2 queries and running them to see if there was any  
difference in the result but there wasn't. Could some body please help  
pointing out the differences of those 2 filters?

# Filtered

# { "query":{ "filtered":{ "query":{ "term" : { "\_type" : "item" } }, "filter":{ "range" : { "price" : { "to" : 1 } } } } } }

# Filter

# { "query":{ "term" : { "\_type" : "item" } }, "filter" : { "range" : { "price" : { "to" : 1 } } } }

Regards,

Ngoc Vo

---

<div class="post-metadata">

**Author:** ![Radim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radim/32/2213_2.png) [@Radim](https://discuss.elastic.co/u/Radim)\
**Post date:** [June 27, 2012, 12:22pm UTC](https://discuss.elastic.co/t/what-are-the-differences-between-filter-and-filtered/8239/2 "2012-06-27T12:22:23Z")

</div>

Hi Ngoc,

the difference is in how facets are counted -- with `filtered`, facets  
are counted from results _after filtering_ (=smaller counts). `filter`  
will count facets from the query results _before filtering_ = greater  
numbers.

It's also mentioned in the docs: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/filter.html)

Best,  
Radim

On Jun 27, 10:50 am, Ngoc Vo [ngoc.vo3...@gmail.com](mailto:ngoc.vo3...@gmail.com) wrote:

> Hi all,
> 
> I'm a newbie in Elastic Search. I got a question subject while researching  
> ES "What are the differences between "filter" and "filtered" ?  
> I tried creating 2 queries and running them to see if there was any  
> difference in the result but there wasn't. Could some body please help  
> pointing out the differences of those 2 filters?
> 
> # Filtered
> 
> {  
> "query":{  
> "filtered":{  
> "query":{  
> "term" : { "\_type" : "item" }},
> 
> "filter":{  
> "range" : {  
> "price" : { "to" : 1 }}  
> }  
> }  
> }  
> }
> 
> =========================
> 
> # Filter
> 
> {  
> "query":{  
> "term" : { "\_type" : "item" }},
> 
> "filter" : {  
> "range" : {  
> "price" : { "to" : 1 }}  
> }  
> }
> 
> =========================
> 
> Regards,
> 
> Ngoc Vo

---

<div class="post-metadata">

**Author:** ![ngocvo3103](https://avatars.discourse-cdn.com/v4/letter/n/aca169/32.png) [@ngocvo3103](https://discuss.elastic.co/u/ngocvo3103)\
**Post date:** [June 28, 2012, 8:51am UTC](https://discuss.elastic.co/t/what-are-the-differences-between-filter-and-filtered/8239/3 "2012-06-28T08:51:54Z")

</div>

Hi Radim,

Thank you for your patience in explaining the differences between those two  
filters. I really appreciate your help.

Regards,  
Ngoc Vo

Vào 19:22:23 UTC+7 Thứ tư, ngày 27 tháng sáu năm 2012, Radim đã viết:

> Hi Ngoc,
> 
> the difference is in how facets are counted -- with `filtered`, facets  
> are counted from results _after filtering_ (=smaller counts). `filter`  
> will count facets from the query results _before filtering_ = greater  
> numbers.
> 
> It's also mentioned in the docs:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/filter.html)
> 
> Best,  
> Radim
> 
> On Jun 27, 10:50 am, Ngoc Vo [ngoc.vo3...@gmail.com](mailto:ngoc.vo3...@gmail.com) wrote:
> 
> > Hi all,
> > 
> > I'm a newbie in Elastic Search. I got a question subject while  
> > researching  
> > ES "What are the differences between "filter" and "filtered" ?  
> > I tried creating 2 queries and running them to see if there was any  
> > difference in the result but there wasn't. Could some body please help  
> > pointing out the differences of those 2 filters?
> > 
> > # Filtered
> > 
> > {  
> > "query":{  
> > "filtered":{  
> > "query":{  
> > "term" : { "\_type" : "item" }},
> > 
> > "filter":{  
> > "range" : {  
> > "price" : { "to" : 1 }}  
> > }  
> > }  
> > }  
> > }
> > 
> > =========================
> > 
> > # Filter
> > 
> > {  
> > "query":{  
> > "term" : { "\_type" : "item" }},
> > 
> > "filter" : {  
> > "range" : {  
> > "price" : { "to" : 1 }}  
> > }  
> > }
> > 
> > =========================
> > 
> > Regards,
> > 
> > Ngoc Vo

---

<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, 3:22am UTC](https://discuss.elastic.co/t/what-are-the-differences-between-filter-and-filtered/8239/4 "2017-07-06T03:22:12Z")

</div>


