# Filter vs Query in ES

**URL:** <https://discuss.elastic.co/t/filter-vs-query-in-es/12007>\
**Category:** Elasticsearch\
**Created:** [May 17, 2013, 8:42am UTC](https://discuss.elastic.co/t/filter-vs-query-in-es/12007 "2013-05-17T08:42:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chetana](https://avatars.discourse-cdn.com/v4/letter/c/dbc845/32.png) [@Chetana](https://discuss.elastic.co/u/Chetana)\
**Post date:** [May 17, 2013, 8:42am UTC](https://discuss.elastic.co/t/filter-vs-query-in-es/12007/1 "2013-05-17T08:42:42Z")

</div>

I am a bit confused betweenFilter(FilterBuilders) and Query(QueryBuilders).  
Whatever possible with FilterBuilder is also achievable using QueryBuilders.  
Is there any case which can only be possible with Filter?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![aash\_dhariya](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@aash\_dhariya](https://discuss.elastic.co/u/aash_dhariya)\
**Post date:** [May 17, 2013, 8:53am UTC](https://discuss.elastic.co/t/filter-vs-query-in-es/12007/2 "2013-05-17T08:53:17Z")

</div>

I think the primary difference between query and filter is that filter is  
cacheable ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/)). Also,  
another major difference, is that filter is not applied on facets, while  
query is.

On Fri, May 17, 2013 at 2:12 PM, Chetana [ambha.career@gmail.com](mailto:ambha.career@gmail.com) wrote:

> I am a bit confused betweenFilter(FilterBuilders) and  
> Query(QueryBuilders). Whatever possible with FilterBuilder is also  
> achievable using QueryBuilders.  
> Is there any case which can only be possible with Filter?
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Thanks,  
Aash

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 17, 2013, 8:55am UTC](https://discuss.elastic.co/t/filter-vs-query-in-es/12007/3 "2013-05-17T08:55:43Z")

</div>

Also note that filters only "filter" docs and are not taken into account when computing score.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 17 mai 2013 à 10:53, aash dhariya [aash.discover@gmail.com](mailto:aash.discover@gmail.com) a écrit :

> I think the primary difference between query and filter is that filter is cacheable ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/)). Also, another major difference, is that filter is not applied on facets, while query is.
> 
> On Fri, May 17, 2013 at 2:12 PM, Chetana [ambha.career@gmail.com](mailto:ambha.career@gmail.com) wrote:
> 
> > ## I am a bit confused betweenFilter(FilterBuilders) and Query(QueryBuilders). Whatever possible with FilterBuilder is also achievable using QueryBuilders. Is there any case which can only be possible with Filter?
> > 
> > You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> ## -- Thanks, Aash
> 
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [May 17, 2013, 11:19am UTC](https://discuss.elastic.co/t/filter-vs-query-in-es/12007/4 "2013-05-17T11:19:44Z")

</div>

On 17 May 2013 10:53, aash dhariya [aash.discover@gmail.com](mailto:aash.discover@gmail.com) wrote:

> Also, another major difference, is that filter is not applied on facets,  
> while query is.

To be clear: filters within the query ARE taken into account by facets, but  
filters specified at the top level of the search request are only applied  
after facets, eg:

```
query: {
    filtered: {
        query: { SOME QUERY },
        filter: { SOME FILTER; TAKEN INTO ACCOUNT BY FACETS }
    }
},
filter: { SOME FILTER; ONLY APPLIED AFTER FACETS }

```

In general, the top-level filter parameter should only be used for this  
purpose. Using it as a general filter will usually result in slower  
performance

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:36am UTC](https://discuss.elastic.co/t/filter-vs-query-in-es/12007/5 "2017-07-06T02:36:06Z")

</div>


