Filtered query + filter vs. filterd + filter only

The subject might be a bit confusing, so let me get straight down to two
different examples:
This assumes a default field "message" [analyzed] is configured for the
query_string query, whereas the fields "name" and "term" are not analysed &
_all is disabled:

A.) Query + filter:

{
"query": {
"filtered": {
"query": {
"query_string": {
"query": "smith"
}
},
"filter": {
"and": [
{
"term": {
"name": "foo"
}
},
{
"term": {
"account": "bar"
}
}
]
}
}
}
}

B.) Filter only:

{
"query": {
"filtered": {
"filter": {
"and": [
{
"term": {
"name": "foo"
}
},
{
"term": {
"account": "bar"
}
},
{
"query": {
"query_string": {
"query": "smith"
}
}
}
]
}
}
}
}

My tests do not show a difference in the generated results.
So, what is the difference?

My understanding is:

  • A filter limits the set that a query runs on
  • I then run a query on the filtered set which is lots faster, since the
    filter is cached.
    ==> this would correspond to A.)

When using filters only, as in "B.)", I would expect that this would be
even faster, since the whole operation is just a reduction of a given set
of documents.

Or does B.) automagically add a "missing" { "query": "match_all": {} }
?

Thanks for enlightening me,

  • Chris

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Anyone?

On Friday, May 31, 2013 3:30:10 PM UTC+2, Chris Kinsalb wrote:

The subject might be a bit confusing, so let me get straight down to two
different examples:
This assumes a default field "message" [analyzed] is configured for the
query_string query, whereas the fields "name" and "term" are not analysed &
_all is disabled:

A.) Query + filter:

{
"query": {
"filtered": {
"query": {
"query_string": {
"query": "smith"
}
},
"filter": {
"and": [
{
"term": {
"name": "foo"
}
},
{
"term": {
"account": "bar"
}
}
]
}
}
}
}

B.) Filter only:

{
"query": {
"filtered": {
"filter": {
"and": [
{
"term": {
"name": "foo"
}
},
{
"term": {
"account": "bar"
}
},
{
"query": {
"query_string": {
"query": "smith"
}
}
}
]
}
}
}
}

My tests do not show a difference in the generated results.
So, what is the difference?

My understanding is:

  • A filter limits the set that a query runs on
  • I then run a query on the filtered set which is lots faster, since the
    filter is cached.
    ==> this would correspond to A.)

When using filters only, as in "B.)", I would expect that this would be
even faster, since the whole operation is just a reduction of a given set
of documents.

Or does B.) automagically add a "missing" { "query": "match_all": {} }
?

Thanks for enlightening me,

  • Chris

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Let me post my assumption here:

B.) will be faster in general, not just because it is a set reduction,
but also (or mainly) since it doesn't involve scoring.

However, my other question still remains: is a *{ "query": "match_all": {}
} or "constant_score" *query automagically added to the filter-only version
(B.)) ?

  • Chris

On Monday, June 3, 2013 8:53:31 AM UTC+2, Chris Kinsalb wrote:

Anyone?

On Friday, May 31, 2013 3:30:10 PM UTC+2, Chris Kinsalb wrote:

The subject might be a bit confusing, so let me get straight down to two
different examples:
This assumes a default field "message" [analyzed] is configured for the
query_string query, whereas the fields "name" and "term" are not analysed &
_all is disabled:

A.) Query + filter:

{
"query": {
"filtered": {
"query": {
"query_string": {
"query": "smith"
}
},
"filter": {
"and": [
{
"term": {
"name": "foo"
}
},
{
"term": {
"account": "bar"
}
}
]
}
}
}
}

B.) Filter only:

{
"query": {
"filtered": {
"filter": {
"and": [
{
"term": {
"name": "foo"
}
},
{
"term": {
"account": "bar"
}
},
{
"query": {
"query_string": {
"query": "smith"
}
}
}
]
}
}
}
}

My tests do not show a difference in the generated results.
So, what is the difference?

My understanding is:

  • A filter limits the set that a query runs on
  • I then run a query on the filtered set which is lots faster, since the
    filter is cached.
    ==> this would correspond to A.)

When using filters only, as in "B.)", I would expect that this would
be even faster, since the whole operation is just a reduction of a given
set of documents.

Or does B.) automagically add a "missing" *{ "query": "match_all": {} }

  • ?

Thanks for enlightening me,

  • Chris

--
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.
For more options, visit https://groups.google.com/groups/opt_out.