# setFilter in Java API

**URL:** https://discuss.elastic.co/t/setfilter-in-java-api/15763
**Category:** Elasticsearch
**Created:** [February 12, 2014, 7:16pm UTC](https://discuss.elastic.co/t/setfilter-in-java-api/15763 "2014-02-12T19:16:41Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Ryan\_Chazen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ryan_chazen/32/1670_2.png) [@Ryan\_Chazen](https://discuss.elastic.co/u/Ryan_Chazen)
#### Post date: [February 12, 2014, 7:16pm UTC](https://discuss.elastic.co/t/setfilter-in-java-api/15763/1 "2014-02-12T19:16:41Z")

</div>

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](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](mailto: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](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](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [February 12, 2014, 7:25pm UTC](https://discuss.elastic.co/t/setfilter-in-java-api/15763/2 "2014-02-12T19:25:21Z")

</div>

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](https://github.com/elasticsearch/elasticsearch/pull/4461)  
[2]  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html)

--  
Ivan

On Wed, Feb 12, 2014 at 11:16 AM, Ryan Chazen [ryanza@gmail.com](mailto: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](http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/search.htmlI) 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](mailto: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](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](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](mailto: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](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](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Ryan\_Chazen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ryan_chazen/32/1670_2.png) [@Ryan\_Chazen](https://discuss.elastic.co/u/Ryan_Chazen)
#### Post date: [February 12, 2014, 7:32pm UTC](https://discuss.elastic.co/t/setfilter-in-java-api/15763/3 "2014-02-12T19:32:21Z")

</div>

Ah great, thanks.

Is this stackoverflow answer incorrect then, or still correct?

> <https://stackoverflow.com/questions/14595988/queries-vs-filters>

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](mailto: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](https://github.com/elasticsearch/elasticsearch/pull/4461)  
> [2]  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html)
> 
> --  
> Ivan
> 
> On Wed, Feb 12, 2014 at 11:16 AM, Ryan Chazen [ryanza@gmail.com](mailto: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](http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/search.htmlI) 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](mailto: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](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](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](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](mailto: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](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](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](mailto: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](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](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [February 12, 2014, 7:46pm UTC](https://discuss.elastic.co/t/setfilter-in-java-api/15763/4 "2014-02-12T19:46:08Z")

</div>

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](mailto:ryanza@gmail.com) wrote:

> Ah great, thanks.
> 
> Is this stackoverflow answer incorrect then, or still correct?
> 
> [elasticsearch - Queries vs. Filters - Stack Overflow](http://stackoverflow.com/questions/14595988/queries-vs-filters)
> 
> 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](mailto: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](https://github.com/elasticsearch/elasticsearch/pull/4461)  
> > [2]  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html)
> > 
> > --  
> > Ivan
> > 
> > On Wed, Feb 12, 2014 at 11:16 AM, Ryan Chazen [ryanza@gmail.com](mailto: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](http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/search.htmlI) 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](mailto: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](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](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](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](mailto: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](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](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](mailto: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](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](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](mailto: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](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](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Ryan\_Chazen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ryan_chazen/32/1670_2.png) [@Ryan\_Chazen](https://discuss.elastic.co/u/Ryan_Chazen)
#### Post date: [February 12, 2014, 8:09pm UTC](https://discuss.elastic.co/t/setfilter-in-java-api/15763/5 "2014-02-12T20:09:05Z")

</div>

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](mailto: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](mailto:ryanza@gmail.com) wrote:
> 
> > Ah great, thanks.
> > 
> > Is this stackoverflow answer incorrect then, or still correct?
> > 
> > [elasticsearch - Queries vs. Filters - Stack Overflow](http://stackoverflow.com/questions/14595988/queries-vs-filters)
> > 
> > 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](mailto: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](https://github.com/elasticsearch/elasticsearch/pull/4461)  
> > > [2]  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html)
> > > 
> > > --  
> > > Ivan
> > > 
> > > On Wed, Feb 12, 2014 at 11:16 AM, Ryan Chazen [ryanza@gmail.com](mailto: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](http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/search.htmlI) 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](mailto: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](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](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](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](mailto: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](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](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](mailto: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](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](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](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](mailto: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](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](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](mailto: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](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](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![zkidkid](https://avatars.discourse-cdn.com/v4/letter/z/fbc32d/32.png) [@zkidkid](https://discuss.elastic.co/u/zkidkid)
#### Post date: [April 3, 2014, 7:32am UTC](https://discuss.elastic.co/t/setfilter-in-java-api/15763/6 "2014-04-03T07:32:38Z")

</div>

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](http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/search.htmlI) 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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/886826d5-5fe2-4c4c-87d6-d8782535efd0%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Ryan\_Chazen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ryan_chazen/32/1670_2.png) [@Ryan\_Chazen](https://discuss.elastic.co/u/Ryan_Chazen)
#### Post date: [April 3, 2014, 7:43am UTC](https://discuss.elastic.co/t/setfilter-in-java-api/15763/7 "2014-04-03T07:43:15Z")

</div>

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](mailto: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](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 a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/xZGnyTI6lmo/unsubscribe](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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/886826d5-5fe2-4c4c-87d6-d8782535efd0%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/886826d5-5fe2-4c4c-87d6-d8782535efd0%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://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](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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/CADawRD1m_oRgW3oWYE5K7s4%3DxvuXyyQCaBpPBCoN5BaJeTWsfw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 6, 2017, 1:38am UTC](https://discuss.elastic.co/t/setfilter-in-java-api/15763/8 "2017-07-06T01:38:37Z")

</div>


