Unscored query vs uncached filter


(Eric Jain) #1

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?


(Shay Banon) #2

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?


(system) #3