# Queries vs Filters

**URL:** <https://discuss.elastic.co/t/queries-vs-filters/21596>\
**Category:** Elasticsearch\
**Created:** [January 13, 2015, 4:53am UTC](https://discuss.elastic.co/t/queries-vs-filters/21596 "2015-01-13T04:53:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Perryn\_Fowler](https://avatars.discourse-cdn.com/v4/letter/p/82dd89/32.png) [@Perryn\_Fowler](https://discuss.elastic.co/u/Perryn_Fowler)\
**Post date:** [January 13, 2015, 4:53am UTC](https://discuss.elastic.co/t/queries-vs-filters/21596/1 "2015-01-13T04:53:53Z")

</div>

Hello,

I am building an application that performs aggregations over time-series  
data.

The prevailing advice for my situation seems to be that I should use  
filters rather than queries to provide scope for my aggregations. The  
reasons being  
1) I have no need for scoring  
2) I will be able to take advantage of filter caching.

However, a very common use case is for my users to scope aggregations to a  
completely arbitrary time range. This means it is relatively unlikely to  
receive many requests scoped to exactly the same time range.

If I implement this using a range filter, does this mean for filter  
caching? Is ElasticSearch going waste time and memory building a separate  
filter cache for each individual range it sees? (and should I hence use a  
query?) Or is it smarter than that?

cheers  
Perryn

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAFps6aCX1BDHDEhU8R7eLhOduerYgNFeAhmgH0kijrbTNZJbAA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAFps6aCX1BDHDEhU8R7eLhOduerYgNFeAhmgH0kijrbTNZJbAA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [January 13, 2015, 5:41am UTC](https://discuss.elastic.co/t/queries-vs-filters/21596/2 "2015-01-13T05:41:00Z")

</div>

Hi ,

Yes , Elasticsearch is going to create filter cache per filter.  
But then if you want to over run this behavior , you can put \_cache as  
false in your query as follows -

```
    "filter" : {
        "fquery" : {
            "query" : {
                "query_string" : {
                    "query" : "this AND that OR thus"
                }
            },
            "_cache" : false
        }

```

Filter cache disable -

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Thanks  
Vineeth Mohan,  
Elasticsearch consultant,  
[qbox.io](http://qbox.io) ( Elasticsearch service provider [http://qbox.io/](http://qbox.io/))

On Tue, Jan 13, 2015 at 10:23 AM, Perryn Fowler [perryn.fowler@gmail.com](mailto:perryn.fowler@gmail.com)  
wrote:

> Hello,
> 
> I am building an application that performs aggregations over time-series  
> data.
> 
> The prevailing advice for my situation seems to be that I should use  
> filters rather than queries to provide scope for my aggregations. The  
> reasons being  
> 1) I have no need for scoring  
> 2) I will be able to take advantage of filter caching.
> 
> However, a very common use case is for my users to scope aggregations to a  
> completely arbitrary time range. This means it is relatively unlikely to  
> receive many requests scoped to exactly the same time range.
> 
> If I implement this using a range filter, does this mean for filter  
> caching? Is Elasticsearch going waste time and memory building a separate  
> filter cache for each individual range it sees? (and should I hence use a  
> query?) Or is it smarter than that?
> 
> cheers  
> Perryn
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CAFps6aCX1BDHDEhU8R7eLhOduerYgNFeAhmgH0kijrbTNZJbAA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAFps6aCX1BDHDEhU8R7eLhOduerYgNFeAhmgH0kijrbTNZJbAA%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CAFps6aCX1BDHDEhU8R7eLhOduerYgNFeAhmgH0kijrbTNZJbAA%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAFps6aCX1BDHDEhU8R7eLhOduerYgNFeAhmgH0kijrbTNZJbAA%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5kH29t3X26MyuSeVvxVKJsiFdw2602kGpjRh3dXb78g0g%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5kH29t3X26MyuSeVvxVKJsiFdw2602kGpjRh3dXb78g0g%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Perryn\_Fowler](https://avatars.discourse-cdn.com/v4/letter/p/82dd89/32.png) [@Perryn\_Fowler](https://discuss.elastic.co/u/Perryn_Fowler)\
**Post date:** [January 13, 2015, 11:21pm UTC](https://discuss.elastic.co/t/queries-vs-filters/21596/3 "2015-01-13T23:21:31Z")

</div>

Thanks vineeth.

I may look at some sort of 'snap to grid' functionality in my app to try  
and get at least some re-use of date ranges.

cheers  
Perryn

On Tue, Jan 13, 2015 at 4:41 PM, vineeth mohan [vm.vineethmohan@gmail.com](mailto:vm.vineethmohan@gmail.com)  
wrote:

> Hi ,
> 
> Yes , Elasticsearch is going to create filter cache per filter.  
> But then if you want to over run this behavior , you can put \_cache as  
> false in your query as follows -
> 
> ```
> "filter" : {
> "fquery" : {
> "query" : {
> "query_string" : {
> "query" : "this AND that OR thus"
> }
> },
> "_cache" : false
> }
> 
> ```
> 
> Filter cache disable -  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-filter.html#_caching_15)
> 
> Thanks  
> Vineeth Mohan,  
> Elasticsearch consultant,  
> [qbox.io](http://qbox.io) ( Elasticsearch service provider [http://qbox.io/](http://qbox.io/))
> 
> On Tue, Jan 13, 2015 at 10:23 AM, Perryn Fowler [perryn.fowler@gmail.com](mailto:perryn.fowler@gmail.com)  
> wrote:
> 
> > Hello,
> > 
> > I am building an application that performs aggregations over time-series  
> > data.
> > 
> > The prevailing advice for my situation seems to be that I should use  
> > filters rather than queries to provide scope for my aggregations. The  
> > reasons being  
> > 1) I have no need for scoring  
> > 2) I will be able to take advantage of filter caching.
> > 
> > However, a very common use case is for my users to scope aggregations to  
> > a completely arbitrary time range. This means it is relatively unlikely to  
> > receive many requests scoped to exactly the same time range.
> > 
> > If I implement this using a range filter, does this mean for filter  
> > caching? Is Elasticsearch going waste time and memory building a separate  
> > filter cache for each individual range it sees? (and should I hence use a  
> > query?) Or is it smarter than that?
> > 
> > cheers  
> > Perryn
> > 
> > --  
> > 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).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/CAFps6aCX1BDHDEhU8R7eLhOduerYgNFeAhmgH0kijrbTNZJbAA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAFps6aCX1BDHDEhU8R7eLhOduerYgNFeAhmgH0kijrbTNZJbAA%40mail.gmail.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/CAFps6aCX1BDHDEhU8R7eLhOduerYgNFeAhmgH0kijrbTNZJbAA%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAFps6aCX1BDHDEhU8R7eLhOduerYgNFeAhmgH0kijrbTNZJbAA%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5kH29t3X26MyuSeVvxVKJsiFdw2602kGpjRh3dXb78g0g%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5kH29t3X26MyuSeVvxVKJsiFdw2602kGpjRh3dXb78g0g%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5kH29t3X26MyuSeVvxVKJsiFdw2602kGpjRh3dXb78g0g%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5kH29t3X26MyuSeVvxVKJsiFdw2602kGpjRh3dXb78g0g%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAFps6aAoEs2D4%3DWrCKf5LqPD-vcgDVXYFR2BCw8ux7dr8D-kvw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAFps6aAoEs2D4%3DWrCKf5LqPD-vcgDVXYFR2BCw8ux7dr8D-kvw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:39am UTC](https://discuss.elastic.co/t/queries-vs-filters/21596/4 "2017-07-06T00:39:10Z")

</div>


