# Unscored query vs uncached filter

**URL:** <https://discuss.elastic.co/t/unscored-query-vs-uncached-filter/6728>\
**Category:** Elasticsearch\
**Created:** [February 16, 2012, 8:31am UTC](https://discuss.elastic.co/t/unscored-query-vs-uncached-filter/6728 "2012-02-16T08:31:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)\
**Post date:** [February 16, 2012, 8:31am UTC](https://discuss.elastic.co/t/unscored-query-vs-uncached-filter/6728/1 "2012-02-16T08:31:44Z")

</div>

Filters are supposed to be more efficient than queries, but is that  
still true if the query is unscored and the filter uncached?

e.g.

{  
"query": {  
"term" : { "user" : "kimchy" }  
},  
"sort" : [  
{ "post\_date" : { "order" : "desc" } }  
],  
"facets" : {  
"tags" : { "terms" : { "field" : "tags" } }  
}  
}

vs

{  
"query": {  
"filtered" : {  
"query" : {  
"match\_all" : { }  
},  
"filter" : {  
"term" : { "user" : "kimchy", "\_cache" : false }  
}  
}  
},  
"sort" : [  
{ "post\_date" : { "order" : "desc" } }  
],  
"facets" : {  
"tags" : { "terms" : { "field" : "tags" } }  
}  
}

btw is there a predictable document order for a match\_all query?

---

<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:** [February 16, 2012, 7:48pm UTC](https://discuss.elastic.co/t/unscored-query-vs-uncached-filter/6728/2 "2012-02-16T19:48:25Z")

</div>

If the term filter is not cached, then no, there isn't a difference (actually the query will be a _bit_ faster, and faster if used in a more complex query, like as a must clause in a bool query).

On Thursday, February 16, 2012 at 10:31 AM, Eric Jain wrote:

> Filters are supposed to be more efficient than queries, but is that  
> still true if the query is unscored and the filter uncached?
> 
> e.g.
> 
> {  
> "query": {  
> "term" : { "user" : "kimchy" }  
> },  
> "sort" : [  
> { "post\_date" : { "order" : "desc" } }  
> ],  
> "facets" : {  
> "tags" : { "terms" : { "field" : "tags" } }  
> }  
> }
> 
> vs
> 
> {  
> "query": {  
> "filtered" : {  
> "query" : {  
> "match\_all" : { }  
> },  
> "filter" : {  
> "term" : { "user" : "kimchy", "\_cache" : false }  
> }  
> }  
> },  
> "sort" : [  
> { "post\_date" : { "order" : "desc" } }  
> ],  
> "facets" : {  
> "tags" : { "terms" : { "field" : "tags" } }  
> }  
> }
> 
> btw is there a predictable document order for a match\_all 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, 3:39am UTC](https://discuss.elastic.co/t/unscored-query-vs-uncached-filter/6728/3 "2017-07-06T03:39:03Z")

</div>


