setFilter in Java API

Hey

I updated to 1.0.0, but I'm getting a strange issue:

As from
http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/search.html
I 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.

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 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%3DcQAEx2KkO%2Bw-9Dr6-A%2BoJ86jeycOfRKDLtvweyweRqDRbQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Ah great, thanks.

Is this stackoverflow answer incorrect then, or still correct?

Namely, which is more efficient: a query, a post filter, or a filter on a
query?

Eg, which one is the best?

  1. setQuery(QueryBuilders.termQuery("multi", "test"))
  2. setPostFilter(FilterBuilders.termFilter("multi", "test"))
  3. 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.

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:

  1. 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.

  1. 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.

  1. 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?

  1. setQuery(QueryBuilders.termQuery("multi", "test"))
  2. setPostFilter(FilterBuilders.termFilter("multi", "test"))
  3. 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.

Great, thank you, that makes it very clear. That explanation should be
added to the query/filter/postfilter docs!

On Wed, Feb 12, 2014 at 9:46 PM, Ivan Brusic ivan@brusic.com wrote:

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:

  1. 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.

  1. 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.

  1. 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?

  1. setQuery(QueryBuilders.termQuery("multi", "test"))
  2. setPostFilter(FilterBuilders.termFilter("multi", "test"))
  3. 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 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%3DcQA_PUgUD8eY%2Bu%3DRWA4AkpJo%3DEs%3DPwW_D%3D7qRo26aNZ9AA%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/CADawRD1KYQC_jhDc%3Ds9TJZBxE427eaDFSgVAWGuNU7nT%2BSPGdw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Ryan Chazen,
Your answer is really clear.
I just want to know in case #2: setPostFilter(...) wil it cached by default
?
Thanks.

On Thursday, February 13, 2014 2:16:41 AM UTC+7, Ryan Chazen 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/886826d5-5fe2-4c4c-87d6-d8782535efd0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi

It was Ivan who gave the answer. I think in case #2 it will not be cached
since the query that is run first is not cached, so the post filter can't
be cached. If you want it to cache you should use case #3

On Thu, Apr 3, 2014 at 9:32 AM, kidkid zkidkid@gmail.com wrote:

Hi Ryan Chazen,
Your answer is really clear.
I just want to know in case #2: setPostFilter(...) wil it cached by
default ?
Thanks.

On Thursday, February 13, 2014 2:16:41 AM UTC+7, Ryan Chazen 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
java-api/current/search.html I 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 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/886826d5-5fe2-4c4c-87d6-d8782535efd0%40googlegroups.comhttps://groups.google.com/d/msgid/elasticsearch/886826d5-5fe2-4c4c-87d6-d8782535efd0%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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/CADawRD1m_oRgW3oWYE5K7s4%3DxvuXyyQCaBpPBCoN5BaJeTWsfw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.