The answer is still correct. What the git commit that I referenced
essentially accomplished was to remove the ambiguity between the different
filters. The filter that is part of a filtered query can be thought of as a
prefilter. Here is the breakdown of what happens in your three cases:
- setQuery(QueryBuilders.termQuery("multi", "test"))
The query gets executed on every document in your index. The documents are
scored depending on the results from the query.
- setPostFilter(FilterBuilders.termFilter("multi", "test"))
The query is executed (matchAll by default if none is found) on all the
documents. After the results are returned by the query, they are then pass
through the filter.
- setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
FilterBuilders.termFilter("multi", "test")))
The filter (which should be cached) is executed first to find the documents
for which the query is run on. Basically, the query should only be executed
on a subset of the documents.
In most cases you want to prefilter since querying is more expensive.
However, sometimes filter can be expensive (geo, scripted) so it might be
better to post filter. Also, facets are calculated on the documents
returned post filter. If you need to facet on the documents before any
filtering, post filters are the way to go. Of course, you can combine the
two types of filters.
Cheers,
Ivan
On Wed, Feb 12, 2014 at 11:32 AM, Ryan Chazen ryanza@gmail.com wrote:
Ah great, thanks.
Is this stackoverflow answer incorrect then, or still correct?
elasticsearch - Queries vs. Filters - Stack Overflow
Namely, which is more efficient: a query, a post filter, or a filter on a
query?
Eg, which one is the best?
- setQuery(QueryBuilders.termQuery("multi", "test"))
- setPostFilter(FilterBuilders.termFilter("multi", "test"))
- setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
FilterBuilders.termFilter("multi", "test")))
I'm guessing 3? But the matchAllQuery() makes it feel like that is wrong...
On Wed, Feb 12, 2014 at 9:25 PM, Ivan Brusic ivan@brusic.com wrote:
The documentation has not been correct for version 1.0 [1]. The method
should be now called setPostFilter. Better yet, you should look into
filtered queries [2].
[1] Renamed top level `filter` to `post_filter`. by martijnvg · Pull Request #4461 · elastic/elasticsearch · GitHub
[2]
Elasticsearch Platform — Find real-time answers at scale | Elastic
--
Ivan
On Wed, Feb 12, 2014 at 11:16 AM, Ryan Chazen ryanza@gmail.com wrote:
Hey
I updated to 1.0.0, but I'm getting a strange issue:
As from
Elasticsearch Platform — Find real-time answers at scale | Elastic tried to run
SearchResponse response = client.prepareSearch("index1", "index2")
.setTypes("type1", "type2")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(QueryBuilders.termQuery("multi", "test")) // Query
.setFilter(FilterBuilders.rangeFilter("age").from(12).to(18)) // Filter
.setFrom(0).setSize(60).setExplain(true)
.execute()
.actionGet();
But I'm getting "The method setFilter(RangeFilterBuilder) is undefined
for the type SearchRequestBuilder"
Any idea?
--
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/c8547981-7429-436f-80a8-f59aa5ab89c7%40googlegroups.com
.
For more options, visit 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/xZGnyTI6lmo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQAEx2KkO%2Bw-9Dr6-A%2BoJ86jeycOfRKDLtvweyweRqDRbQ%40mail.gmail.com
.
For more options, visit 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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CADawRD0PanTaF9gzj-ncFb_V74igqGkD_XyQfa72aA%3DuCUhL8w%40mail.gmail.com
.
For more options, visit 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQA_PUgUD8eY%2Bu%3DRWA4AkpJo%3DEs%3DPwW_D%3D7qRo26aNZ9AA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.