# Filter and Query same taking some time

**URL:** <https://discuss.elastic.co/t/filter-and-query-same-taking-some-time/15157>\
**Category:** Elasticsearch\
**Created:** [January 9, 2014, 5:14am UTC](https://discuss.elastic.co/t/filter-and-query-same-taking-some-time/15157 "2014-01-09T05:14:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arjit\_Gupta](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Arjit\_Gupta](https://discuss.elastic.co/u/Arjit_Gupta)\
**Post date:** [January 9, 2014, 5:14am UTC](https://discuss.elastic.co/t/filter-and-query-same-taking-some-time/15157/1 "2014-01-09T05:14:02Z")

</div>

Hi,

I had implemented ES search query for all our use cases but when i came to  
know that some of our use cases can be solved by filters I implemented that  
but I dont see any gain (in response time) in filters. My search queries  
are

1. Filter

{  
"size" : 100,  
"query" : {  
"match\_all" : { }  
},  
"filter" : {  
"bool" : {  
"must" : {  
"term" : {  
"color" : "red"  
}  
}  
}  
},  
"version" : true  
}

1. Query

{  
"size" : 100,  
"query" : {  
"bool" : {  
"must" : {  
"match" : {  
"color" : {  
"query" : "red",  
"type" : "boolean",  
"operator" : "AND"  
}  
}  
}  
}  
},  
"version" : true  
}

By default the term query should be cached but I dont see a performance  
gain.  
Do i need to change some parameter also ?  
I am using ES 0.90.1 and with 16Gb of heap space given to ES.

Thanks,  
Arjit

--  
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/326a6640-d887-46b4-a8e7-ec15a1c9dc98%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/326a6640-d887-46b4-a8e7-ec15a1c9dc98%40googlegroups.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:** [January 9, 2014, 7:36am UTC](https://discuss.elastic.co/t/filter-and-query-same-taking-some-time/15157/2 "2014-01-09T07:36:59Z")

</div>

You probably won't see any difference the first time you execute it unless you are using warmers.  
With a second query, you should see the difference.

How many documents you have in your dataset?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 9 janvier 2014 at 06:14:06, Arjit Gupta ([arjit292@gmail.com](mailto:arjit292@gmail.com)) a écrit:

Hi,

I had implemented ES search query for all our use cases but when i came to know that some of our use cases can be solved by filters I implemented that but I dont see any gain (in response time) in filters. My search queries are

1. Filter

{  
"size" : 100,  
"query" : {  
"match\_all" : { }  
},  
"filter" : {  
"bool" : {  
"must" : {  
"term" : {  
"color" : "red"  
}  
}  
}  
},  
"version" : true  
}

1. Query

{  
"size" : 100,  
"query" : {  
"bool" : {  
"must" : {  
"match" : {  
"color" : {  
"query" : "red",  
"type" : "boolean",  
"operator" : "AND"  
}  
}  
}  
}  
},  
"version" : true  
}

By default the term query should be cached but I dont see a performance gain.  
Do i need to change some parameter also ?  
I am using ES 0.90.1 and with 16Gb of heap space given to ES.

## Thanks, Arjit

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/326a6640-d887-46b4-a8e7-ec15a1c9dc98%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/326a6640-d887-46b4-a8e7-ec15a1c9dc98%40googlegroups.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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/etPan.52ce519b.75c6c33a.1449b%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.52ce519b.75c6c33a.1449b%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Arjit\_Gupta](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Arjit\_Gupta](https://discuss.elastic.co/u/Arjit_Gupta)\
**Post date:** [January 9, 2014, 7:43am UTC](https://discuss.elastic.co/t/filter-and-query-same-taking-some-time/15157/3 "2014-01-09T07:43:09Z")

</div>

I have 100,000 documents which are similar. In response I am getting the  
whole document not just Id.  
I am executing the query multiple times.

Thanks ,  
Arjit

On Thu, Jan 9, 2014 at 1:06 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> You probably won't see any difference the first time you execute it unless  
> you are using warmers.  
> With a second query, you should see the difference.
> 
> How many documents you have in your dataset?
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> 
> Le 9 janvier 2014 at 06:14:06, Arjit Gupta ([arjit292@gmail.com](mailto:arjit292@gmail.com)//arjit292@gmail.com)  
> a écrit:
> 
> Hi,
> 
> I had implemented ES search query for all our use cases but when i came  
> to know that some of our use cases can be solved by filters I implemented  
> that but I dont see any gain (in response time) in filters. My search  
> queries are
> 
> 1. Filter
> 
> {  
> "size" : 100,  
> "query" : {  
> "match\_all" : { }  
> },  
> "filter" : {  
> "bool" : {  
> "must" : {  
> "term" : {  
> "color" : "red"  
> }  
> }  
> }  
> },  
> "version" : true  
> }
> 
> 1. Query
> 
> {  
> "size" : 100,  
> "query" : {  
> "bool" : {  
> "must" : {  
> "match" : {  
> "color" : {  
> "query" : "red",  
> "type" : "boolean",  
> "operator" : "AND"  
> }  
> }  
> }  
> }  
> },  
> "version" : true  
> }
> 
> By default the term query should be cached but I dont see a performance  
> gain.  
> Do i need to change some parameter also ?  
> I am using ES 0.90.1 and with 16Gb of heap space given to ES.
> 
> ## Thanks, Arjit
> 
> 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/326a6640-d887-46b4-a8e7-ec15a1c9dc98%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/326a6640-d887-46b4-a8e7-ec15a1c9dc98%40googlegroups.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 a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/uknnBHMnZLk/unsubscribe](https://groups.google.com/d/topic/elasticsearch/uknnBHMnZLk/unsubscribe).  
> To unsubscribe from this group and all its topics, 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/etPan.52ce519b.75c6c33a.1449b%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.52ce519b.75c6c33a.1449b%40MacBook-Air-de-David.local)  
> .
> 
> 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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CADe%2BHd-RzJxTrtt8gVOS6cxa%3DXNZ%3Dwa%2Bv8Vnwnqigd5gfnJ0fw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CADe%2BHd-RzJxTrtt8gVOS6cxa%3DXNZ%3Dwa%2Bv8Vnwnqigd5gfnJ0fw%40mail.gmail.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:** [January 9, 2014, 7:45am UTC](https://discuss.elastic.co/t/filter-and-query-same-taking-some-time/15157/4 "2014-01-09T07:45:36Z")

</div>

Yeah 100000 documents is not that much!  
Not sure if you can notice a difference here as probably everything could be loaded in file system cache.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 9 janvier 2014 at 08:43:13, Arjit Gupta ([arjit292@gmail.com](mailto:arjit292@gmail.com)) a écrit:

I have 100,000 documents which are similar. In response I am getting the whole document not just Id.  
I am executing the query multiple times.

Thanks ,  
Arjit

On Thu, Jan 9, 2014 at 1:06 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:  
You probably won't see any difference the first time you execute it unless you are using warmers.  
With a second query, you should see the difference.

How many documents you have in your dataset?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 9 janvier 2014 at 06:14:06, Arjit Gupta ([arjit292@gmail.com](mailto:arjit292@gmail.com)) a écrit:

Hi,

I had implemented ES search query for all our use cases but when i came to know that some of our use cases can be solved by filters I implemented that but I dont see any gain (in response time) in filters. My search queries are

1. Filter

{  
"size" : 100,  
"query" : {  
"match\_all" : { }  
},  
"filter" : {  
"bool" : {  
"must" : {  
"term" : {  
"color" : "red"  
}  
}  
}  
},  
"version" : true  
}

1. Query

{  
"size" : 100,  
"query" : {  
"bool" : {  
"must" : {  
"match" : {  
"color" : {  
"query" : "red",  
"type" : "boolean",  
"operator" : "AND"  
}  
}  
}  
}  
},  
"version" : true  
}

By default the term query should be cached but I dont see a performance gain.  
Do i need to change some parameter also ?  
I am using ES 0.90.1 and with 16Gb of heap space given to ES.

## Thanks, Arjit

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/326a6640-d887-46b4-a8e7-ec15a1c9dc98%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/326a6640-d887-46b4-a8e7-ec15a1c9dc98%40googlegroups.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 a topic in the Google Groups "elasticsearch" group.  
To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/uknnBHMnZLk/unsubscribe](https://groups.google.com/d/topic/elasticsearch/uknnBHMnZLk/unsubscribe).  
To unsubscribe from this group and all its topics, 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/etPan.52ce519b.75c6c33a.1449b%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.52ce519b.75c6c33a.1449b%40MacBook-Air-de-David.local).

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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CADe%2BHd-RzJxTrtt8gVOS6cxa%3DXNZ%3Dwa%2Bv8Vnwnqigd5gfnJ0fw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CADe%2BHd-RzJxTrtt8gVOS6cxa%3DXNZ%3Dwa%2Bv8Vnwnqigd5gfnJ0fw%40mail.gmail.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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/etPan.52ce53a0.275ac794.1449b%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.52ce53a0.275ac794.1449b%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Arjit\_Gupta](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Arjit\_Gupta](https://discuss.elastic.co/u/Arjit_Gupta)\
**Post date:** [January 9, 2014, 7:52am UTC](https://discuss.elastic.co/t/filter-and-query-same-taking-some-time/15157/5 "2014-01-09T07:52:58Z")

</div>

My app is index heavy so we are putting a lot of documents and also  
searching in mean while (using it as datastore).  
Most of the time the threads are stuck on merge if segments. Can you  
suggest us some optimizations ?

Thanks ,  
Arjit

On Thu, Jan 9, 2014 at 1:15 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Yeah 100000 documents is not that much!  
> Not sure if you can notice a difference here as probably everything could  
> be loaded in file system cache.
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> 
> Le 9 janvier 2014 at 08:43:13, Arjit Gupta ([arjit292@gmail.com](mailto:arjit292@gmail.com)//arjit292@gmail.com)  
> a écrit:
> 
> I have 100,000 documents which are similar. In response I am getting the  
> whole document not just Id.  
> I am executing the query multiple times.
> 
> Thanks ,  
> Arjit
> 
> On Thu, Jan 9, 2014 at 1:06 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> 
> > You probably won't see any difference the first time you execute it  
> > unless you are using warmers.  
> > With a second query, you should see the difference.
> > 
> > How many documents you have in your dataset?
> > 
> > ```
> > --
> > 
> > ```
> > 
> > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > 
> > Le 9 janvier 2014 at 06:14:06, Arjit Gupta ([arjit292@gmail.com](mailto:arjit292@gmail.com)//arjit292@gmail.com)  
> > a écrit:
> > 
> > Hi,
> > 
> > I had implemented ES search query for all our use cases but when i came  
> > to know that some of our use cases can be solved by filters I implemented  
> > that but I dont see any gain (in response time) in filters. My search  
> > queries are
> > 
> > 1. Filter
> > 
> > {  
> > "size" : 100,  
> > "query" : {  
> > "match\_all" : { }  
> > },  
> > "filter" : {  
> > "bool" : {  
> > "must" : {  
> > "term" : {  
> > "color" : "red"  
> > }  
> > }  
> > }  
> > },  
> > "version" : true  
> > }
> > 
> > 1. Query
> > 
> > {  
> > "size" : 100,  
> > "query" : {  
> > "bool" : {  
> > "must" : {  
> > "match" : {  
> > "color" : {  
> > "query" : "red",  
> > "type" : "boolean",  
> > "operator" : "AND"  
> > }  
> > }  
> > }  
> > }  
> > },  
> > "version" : true  
> > }
> > 
> > By default the term query should be cached but I dont see a performance  
> > gain.  
> > Do i need to change some parameter also ?  
> > I am using ES 0.90.1 and with 16Gb of heap space given to ES.
> > 
> > ## Thanks, Arjit
> > 
> > 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/326a6640-d887-46b4-a8e7-ec15a1c9dc98%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/326a6640-d887-46b4-a8e7-ec15a1c9dc98%40googlegroups.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 a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/uknnBHMnZLk/unsubscribe](https://groups.google.com/d/topic/elasticsearch/uknnBHMnZLk/unsubscribe).  
> > To unsubscribe from this group and all its topics, 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/etPan.52ce519b.75c6c33a.1449b%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.52ce519b.75c6c33a.1449b%40MacBook-Air-de-David.local).
> > 
> > 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CADe%2BHd-RzJxTrtt8gVOS6cxa%3DXNZ%3Dwa%2Bv8Vnwnqigd5gfnJ0fw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CADe%2BHd-RzJxTrtt8gVOS6cxa%3DXNZ%3Dwa%2Bv8Vnwnqigd5gfnJ0fw%40mail.gmail.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 a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/uknnBHMnZLk/unsubscribe](https://groups.google.com/d/topic/elasticsearch/uknnBHMnZLk/unsubscribe).  
> To unsubscribe from this group and all its topics, 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/etPan.52ce53a0.275ac794.1449b%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.52ce53a0.275ac794.1449b%40MacBook-Air-de-David.local)  
> .
> 
> 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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CADe%2BHd9A8afFnL\_xaa%3D%2BpHRETfmcWqDv-81mOo7np4xNvJ41cA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CADe%2BHd9A8afFnL_xaa%3D%2BpHRETfmcWqDv-81mOo7np4xNvJ41cA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Arjit\_Gupta](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Arjit\_Gupta](https://discuss.elastic.co/u/Arjit_Gupta)\
**Post date:** [January 9, 2014, 9:13am UTC](https://discuss.elastic.co/t/filter-and-query-same-taking-some-time/15157/6 "2014-01-09T09:13:28Z")

</div>

I had 13 Million documents and with the same query  
I see Filters performing worse then query  
filters are taking 400ms where as query is taking 300 ms

1. Filter

{  
"size" : 100,  
"query" : {  
"match\_all" : { }  
},  
"filter" : {  
"bool" : {  
"must" : {  
"term" : {  
"color" : "red"  
}  
}  
}  
},  
"version" : true  
}

1. Query

{  
"size" : 100,  
"query" : {  
"bool" : {  
"must" : {  
"match" : {  
"color" : {  
"query" : "red",  
"type" : "boolean",  
"operator" : "AND"  
}  
}  
}  
}  
},  
"version" : true  
}

Thanks ,  
Arjit

On Thu, Jan 9, 2014 at 1:15 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Yeah 100000 documents is not that much!  
> Not sure if you can notice a difference here as probably everything could  
> be loaded in file system cache.
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> 
> Le 9 janvier 2014 at 08:43:13, Arjit Gupta ([arjit292@gmail.com](mailto:arjit292@gmail.com)//arjit292@gmail.com)  
> a écrit:
> 
> I have 100,000 documents which are similar. In response I am getting the  
> whole document not just Id.  
> I am executing the query multiple times.
> 
> Thanks ,  
> Arjit
> 
> On Thu, Jan 9, 2014 at 1:06 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> 
> > You probably won't see any difference the first time you execute it  
> > unless you are using warmers.  
> > With a second query, you should see the difference.
> > 
> > How many documents you have in your dataset?
> > 
> > ```
> > --
> > 
> > ```
> > 
> > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > 
> > Le 9 janvier 2014 at 06:14:06, Arjit Gupta ([arjit292@gmail.com](mailto:arjit292@gmail.com)//arjit292@gmail.com)  
> > a écrit:
> > 
> > Hi,
> > 
> > I had implemented ES search query for all our use cases but when i came  
> > to know that some of our use cases can be solved by filters I implemented  
> > that but I dont see any gain (in response time) in filters. My search  
> > queries are
> > 
> > 1. Filter
> > 
> > {  
> > "size" : 100,  
> > "query" : {  
> > "match\_all" : { }  
> > },  
> > "filter" : {  
> > "bool" : {  
> > "must" : {  
> > "term" : {  
> > "color" : "red"  
> > }  
> > }  
> > }  
> > },  
> > "version" : true  
> > }
> > 
> > 1. Query
> > 
> > {  
> > "size" : 100,  
> > "query" : {  
> > "bool" : {  
> > "must" : {  
> > "match" : {  
> > "color" : {  
> > "query" : "red",  
> > "type" : "boolean",  
> > "operator" : "AND"  
> > }  
> > }  
> > }  
> > }  
> > },  
> > "version" : true  
> > }
> > 
> > By default the term query should be cached but I dont see a performance  
> > gain.  
> > Do i need to change some parameter also ?  
> > I am using ES 0.90.1 and with 16Gb of heap space given to ES.
> > 
> > ## Thanks, Arjit
> > 
> > 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/326a6640-d887-46b4-a8e7-ec15a1c9dc98%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/326a6640-d887-46b4-a8e7-ec15a1c9dc98%40googlegroups.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 a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/uknnBHMnZLk/unsubscribe](https://groups.google.com/d/topic/elasticsearch/uknnBHMnZLk/unsubscribe).  
> > To unsubscribe from this group and all its topics, 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/etPan.52ce519b.75c6c33a.1449b%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.52ce519b.75c6c33a.1449b%40MacBook-Air-de-David.local).
> > 
> > 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CADe%2BHd-RzJxTrtt8gVOS6cxa%3DXNZ%3Dwa%2Bv8Vnwnqigd5gfnJ0fw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CADe%2BHd-RzJxTrtt8gVOS6cxa%3DXNZ%3Dwa%2Bv8Vnwnqigd5gfnJ0fw%40mail.gmail.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 a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/uknnBHMnZLk/unsubscribe](https://groups.google.com/d/topic/elasticsearch/uknnBHMnZLk/unsubscribe).  
> To unsubscribe from this group and all its topics, 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/etPan.52ce53a0.275ac794.1449b%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.52ce53a0.275ac794.1449b%40MacBook-Air-de-David.local)  
> .
> 
> 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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CADe%2BHd\_sRevprSV7U%2BSHiCPQ5O%2BFOncjnVg1ko%2BmG53zMriGGg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CADe%2BHd_sRevprSV7U%2BSHiCPQ5O%2BFOncjnVg1ko%2BmG53zMriGGg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![mattweber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattweber/32/44940_2.png) [@mattweber](https://discuss.elastic.co/u/mattweber)\
**Post date:** [January 9, 2014, 3:49pm UTC](https://discuss.elastic.co/t/filter-and-query-same-taking-some-time/15157/7 "2014-01-09T15:49:33Z")

</div>

Use a filtered query, not an outer filter. You only want to use that  
outer filter when you are faceting and don't want the filter to change the  
facet counts.

> **[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,  
Matt Weber

On Thu, Jan 9, 2014 at 1:13 AM, Arjit Gupta [arjit292@gmail.com](mailto:arjit292@gmail.com) wrote:

> I had 13 Million documents and with the same query  
> I see Filters performing worse then query  
> filters are taking 400ms where as query is taking 300 ms
> 
> 1. Filter
> 
> {  
> "size" : 100,  
> "query" : {  
> "match\_all" : { }  
> },  
> "filter" : {  
> "bool" : {  
> "must" : {  
> "term" : {  
> "color" : "red"  
> }  
> }  
> }  
> },  
> "version" : true  
> }
> 
> 1. Query
> 
> {  
> "size" : 100,  
> "query" : {  
> "bool" : {  
> "must" : {  
> "match" : {  
> "color" : {  
> "query" : "red",  
> "type" : "boolean",  
> "operator" : "AND"  
> }  
> }  
> }  
> }  
> },  
> "version" : true  
> }
> 
> Thanks ,  
> Arjit
> 
> On Thu, Jan 9, 2014 at 1:15 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> 
> > Yeah 100000 documents is not that much!  
> > Not sure if you can notice a difference here as probably everything could  
> > be loaded in file system cache.
> > 
> > --  
> > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > 
> > Le 9 janvier 2014 at 08:43:13, Arjit Gupta ([arjit292@gmail.com](mailto:arjit292@gmail.com)//arjit292@gmail.com)  
> > a écrit:
> > 
> > I have 100,000 documents which are similar. In response I am getting the  
> > whole document not just Id.  
> > I am executing the query multiple times.
> > 
> > Thanks ,  
> > Arjit
> > 
> > On Thu, Jan 9, 2014 at 1:06 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> > 
> > > You probably won't see any difference the first time you execute it  
> > > unless you are using warmers.  
> > > With a second query, you should see the difference.
> > > 
> > > How many documents you have in your dataset?
> > > 
> > > ```
> > > --
> > > 
> > > ```
> > > 
> > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > > 
> > > Le 9 janvier 2014 at 06:14:06, Arjit Gupta ([arjit292@gmail.com](mailto:arjit292@gmail.com)//arjit292@gmail.com)  
> > > a écrit:
> > > 
> > > Hi,
> > > 
> > > I had implemented ES search query for all our use cases but when i came  
> > > to know that some of our use cases can be solved by filters I implemented  
> > > that but I dont see any gain (in response time) in filters. My search  
> > > queries are
> > > 
> > > 1. Filter
> > > 
> > > {  
> > > "size" : 100,  
> > > "query" : {  
> > > "match\_all" : { }  
> > > },  
> > > "filter" : {  
> > > "bool" : {  
> > > "must" : {  
> > > "term" : {  
> > > "color" : "red"  
> > > }  
> > > }  
> > > }  
> > > },  
> > > "version" : true  
> > > }
> > > 
> > > 1. Query
> > > 
> > > {  
> > > "size" : 100,  
> > > "query" : {  
> > > "bool" : {  
> > > "must" : {  
> > > "match" : {  
> > > "color" : {  
> > > "query" : "red",  
> > > "type" : "boolean",  
> > > "operator" : "AND"  
> > > }  
> > > }  
> > > }  
> > > }  
> > > },  
> > > "version" : true  
> > > }
> > > 
> > > By default the term query should be cached but I dont see a performance  
> > > gain.  
> > > Do i need to change some parameter also ?  
> > > I am using ES 0.90.1 and with 16Gb of heap space given to ES.
> > > 
> > > ## Thanks, Arjit
> > > 
> > > 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/326a6640-d887-46b4-a8e7-ec15a1c9dc98%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/326a6640-d887-46b4-a8e7-ec15a1c9dc98%40googlegroups.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 a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit  
> > > [https://groups.google.com/d/topic/elasticsearch/uknnBHMnZLk/unsubscribe](https://groups.google.com/d/topic/elasticsearch/uknnBHMnZLk/unsubscribe).  
> > > To unsubscribe from this group and all its topics, 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/etPan.52ce519b.75c6c33a.1449b%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.52ce519b.75c6c33a.1449b%40MacBook-Air-de-David.local).
> > > 
> > > 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).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/CADe%2BHd-RzJxTrtt8gVOS6cxa%3DXNZ%3Dwa%2Bv8Vnwnqigd5gfnJ0fw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CADe%2BHd-RzJxTrtt8gVOS6cxa%3DXNZ%3Dwa%2Bv8Vnwnqigd5gfnJ0fw%40mail.gmail.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 a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/uknnBHMnZLk/unsubscribe](https://groups.google.com/d/topic/elasticsearch/uknnBHMnZLk/unsubscribe).  
> > To unsubscribe from this group and all its topics, 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/etPan.52ce53a0.275ac794.1449b%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.52ce53a0.275ac794.1449b%40MacBook-Air-de-David.local)  
> > .
> > 
> > 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CADe%2BHd\_sRevprSV7U%2BSHiCPQ5O%2BFOncjnVg1ko%2BmG53zMriGGg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CADe%2BHd_sRevprSV7U%2BSHiCPQ5O%2BFOncjnVg1ko%2BmG53zMriGGg%40mail.gmail.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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAJ3KEoAz7P3RteL3ksj-iQTYc1F9yXKmF8jg92v0oLnH0wwgdg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAJ3KEoAz7P3RteL3ksj-iQTYc1F9yXKmF8jg92v0oLnH0wwgdg%40mail.gmail.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, 1:57am UTC](https://discuss.elastic.co/t/filter-and-query-same-taking-some-time/15157/8 "2017-07-06T01:57:40Z")

</div>


