ES FILTERED QUERY filers first with terms (cheap) and then match(expensive), or otherwise?

So I suppose that when I run a filtered query like this one, ES filters all
the documents in the database, and then performs the match query only to
the documents that fit the filter, right? I just want to make sure that it
doesn't perform the match query on all the documents and the drop the ones
that don't fit the filter, because that would be a total waste of resources
as I'm only interested on a small portion of the documents.

{
"query" : {
"filtered" : {
"query": {
"match": {
"field1": "whatever"
}
},
"filter" : {
"term" : {
"field2" : 10
}
}
}
}
}

Thanks for clarifying this!

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/ee8f3294-9761-4d7b-b8b1-e49943d88ae7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yup

On Wednesday, January 28, 2015 at 12:46:58 AM UTC+1, Gabriel Gavilan
gavilán wrote:

So I suppose that when I run a filtered query like this one, ES filters
all the documents in the database, and then performs the match query only
to the documents that fit the filter, right? I just want to make sure that
it doesn't perform the match query on all the documents and the drop the
ones that don't fit the filter, because that would be a total waste of
resources as I'm only interested on a small portion of the documents.

{
"query" : {
"filtered" : {
"query": {
"match": {
"field1": "whatever"
}
},
"filter" : {
"term" : {
"field2" : 10
}
}
}
}
}

Thanks for clarifying this!

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/3827c690-9a0b-43b0-9502-adaf020141bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

You're right.

And there is also the post_filter (formerly known as "filter")
(Elasticsearch Platform — Find real-time answers at scale | Elastic)
which starts with the query and ends with the filtering.

On Wednesday, January 28, 2015 at 12:46:58 AM UTC+1, Gabriel Gavilan
gavilán wrote:

So I suppose that when I run a filtered query like this one, ES filters
all the documents in the database, and then performs the match query only
to the documents that fit the filter, right? I just want to make sure that
it doesn't perform the match query on all the documents and the drop the
ones that don't fit the filter, because that would be a total waste of
resources as I'm only interested on a small portion of the documents.

{
"query" : {
"filtered" : {
"query": {
"match": {
"field1": "whatever"
}
},
"filter" : {
"term" : {
"field2" : 10
}
}
}
}
}

Thanks for clarifying this!

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/ca46ccaa-dc6a-4827-b795-6ff23cad7b6d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.