# Adding filters to percolator query

**URL:** <https://discuss.elastic.co/t/adding-filters-to-percolator-query/6579>\
**Category:** Elasticsearch\
**Created:** [February 3, 2012, 4:37am UTC](https://discuss.elastic.co/t/adding-filters-to-percolator-query/6579 "2012-02-03T04:37:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vibin](https://avatars.discourse-cdn.com/v4/letter/v/2bfe46/32.png) [@vibin](https://discuss.elastic.co/u/vibin)\
**Post date:** [February 3, 2012, 4:37am UTC](https://discuss.elastic.co/t/adding-filters-to-percolator-query/6579/1 "2012-02-03T04:37:34Z")

</div>

Hi,

After understanding the basic concepts of Percolator, I started adding  
query as well as filter to a percolator, but it seems like, somewhere  
went wrong and the percolator is considering only the query while  
pulling the results and filters are getting ignored.

I am not sure if Percolator supports filter along with query. Then I  
tried adding those filter conditions as multiple queries and that too  
failed. So, how can I achieve adding a complete search(with query and  
filter) in Percolator?

Below is the code snippet I am using for this. Please let me know if I  
am wrong any where

BoolQueryBuilder qb = new BoolQueryBuilder();  
qb.must(termQuery("field1","value"));  
qb.must(termQuery("field2","value"));  
client.prepareIndex("\_percolator", "alert", "id1")  
.setSource(XContentFactory.jsonBuilder().startObject().field("query",  
qb).endObject())  
.setRefresh(true).setRouting(index)  
.execute().actionGet();

Cheers,

- Vibin

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 5, 2012, 11:28am UTC](https://discuss.elastic.co/t/adding-filters-to-percolator-query/6579/2 "2012-02-05T11:28:18Z")

</div>

percolator support boolean query / filters. Gist a full recreation and we can have a look at it ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)).

On Friday, February 3, 2012 at 6:37 AM, vibin dhas wrote:

> Hi,
> 
> After understanding the basic concepts of Percolator, I started adding  
> query as well as filter to a percolator, but it seems like, somewhere  
> went wrong and the percolator is considering only the query while  
> pulling the results and filters are getting ignored.
> 
> I am not sure if Percolator supports filter along with query. Then I  
> tried adding those filter conditions as multiple queries and that too  
> failed. So, how can I achieve adding a complete search(with query and  
> filter) in Percolator?
> 
> Below is the code snippet I am using for this. Please let me know if I  
> am wrong any where
> 
> BoolQueryBuilder qb = new BoolQueryBuilder();  
> qb.must(termQuery("field1","value"));  
> qb.must(termQuery("field2","value"));  
> client.prepareIndex("\_percolator", "alert", "id1")  
> .setSource(XContentFactory.jsonBuilder().startObject().field("query",  
> qb).endObject())  
> .setRefresh(true).setRouting(index)  
> .execute().actionGet();
> 
> Cheers,
> 
> - Vibin

---

<div class="post-metadata">

**Author:** ![vibin](https://avatars.discourse-cdn.com/v4/letter/v/2bfe46/32.png) [@vibin](https://discuss.elastic.co/u/vibin)\
**Post date:** [February 7, 2012, 2:08pm UTC](https://discuss.elastic.co/t/adding-filters-to-percolator-query/6579/3 "2012-02-07T14:08:40Z")

</div>

sure, the gist is here...

> <https://gist.github.com/Manokrrish/1757759>

I have given the CURL and the query, which I am using to create a  
Percolator...

Like I said above, after setting the query, when I index documents  
irrelevant results returned. Filters are ignored from the Percolator  
query.

On Feb 5, 4:28 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> percolator support boolean query / filters. Gist a full recreation and we can have a look at it ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)).
> 
> On Friday, February 3, 2012 at 6:37 AM, vibin dhas wrote:
> 
> > Hi,
> 
> > After understanding the basic concepts of Percolator, I started adding  
> > query as well as filter to a percolator, but it seems like, somewhere  
> > went wrong and the percolator is considering only the query while  
> > pulling the results and filters are getting ignored.
> 
> > I am not sure if Percolator supports filter along with query. Then I  
> > tried adding those filter conditions as multiple queries and that too  
> > failed. So, how can I achieve adding a complete search(with query and  
> > filter) in Percolator?
> 
> > Below is the code snippet I am using for this. Please let me know if I  
> > am wrong any where
> 
> > BoolQueryBuilder qb = new BoolQueryBuilder();  
> > qb.must(termQuery("field1","value"));  
> > qb.must(termQuery("field2","value"));  
> > client.prepareIndex("\_percolator", "alert", "id1")  
> > .setSource(XContentFactory.jsonBuilder().startObject().field("query",  
> > qb).endObject())  
> > .setRefresh(true).setRouting(index)  
> > .execute().actionGet();
> 
> > Cheers,
> > 
> > - Vibin

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 7, 2012, 6:49pm UTC](https://discuss.elastic.co/t/adding-filters-to-percolator-query/6579/4 "2012-02-07T18:49:27Z")

</div>

Your structure is incorrect. In order to use a filter, you need to wrap it in a filtered query. I've added a comment with the current format.

On Tuesday, February 7, 2012 at 4:08 PM, vibin dhas wrote:

> sure, the gist is here...
> 
> [problem while passing filter to set Percolator · GitHub](https://gist.github.com/1757759)
> 
> I have given the CURL and the query, which I am using to create a  
> Percolator...
> 
> Like I said above, after setting the query, when I index documents  
> irrelevant results returned. Filters are ignored from the Percolator  
> query.
> 
> On Feb 5, 4:28 pm, Shay Banon \<[kim...@gmail.com](mailto:kim...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> 
> > percolator support boolean query / filters. Gist a full recreation and we can have a look at it ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)).
> > 
> > On Friday, February 3, 2012 at 6:37 AM, vibin dhas wrote:
> > 
> > > Hi,
> > 
> > > After understanding the basic concepts of Percolator, I started adding  
> > > query as well as filter to a percolator, but it seems like, somewhere  
> > > went wrong and the percolator is considering only the query while  
> > > pulling the results and filters are getting ignored.
> > 
> > > I am not sure if Percolator supports filter along with query. Then I  
> > > tried adding those filter conditions as multiple queries and that too  
> > > failed. So, how can I achieve adding a complete search(with query and  
> > > filter) in Percolator?
> > 
> > > Below is the code snippet I am using for this. Please let me know if I  
> > > am wrong any where
> > 
> > > BoolQueryBuilder qb = new BoolQueryBuilder();  
> > > qb.must(termQuery("field1","value"));  
> > > qb.must(termQuery("field2","value"));  
> > > client.prepareIndex("\_percolator", "alert", "id1")  
> > > .setSource(XContentFactory.jsonBuilder().startObject().field("query",  
> > > qb).endObject())  
> > > .setRefresh(true).setRouting(index)  
> > > .execute().actionGet();
> > 
> > > Cheers,
> > > 
> > > - Vibin

---

<div class="post-metadata">

**Author:** ![vibin](https://avatars.discourse-cdn.com/v4/letter/v/2bfe46/32.png) [@vibin](https://discuss.elastic.co/u/vibin)\
**Post date:** [February 8, 2012, 7:19am UTC](https://discuss.elastic.co/t/adding-filters-to-percolator-query/6579/5 "2012-02-08T07:19:31Z")

</div>

Its working now.

Thanks for your help with this, Shay.

-Vibin

On Feb 7, 11:49 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Your structure is incorrect. In order to use a filter, you need to wrap it in a filtered query. I've added a comment with the current format.
> 
> On Tuesday, February 7, 2012 at 4:08 PM, vibin dhas wrote:
> 
> > sure, the gist is here...
> 
> > [problem while passing filter to set Percolator · GitHub](https://gist.github.com/1757759)
> 
> > I have given the CURL and the query, which I am using to create a  
> > Percolator...
> 
> > Like I said above, after setting the query, when I index documents  
> > irrelevant results returned. Filters are ignored from the Percolator  
> > query.
> 
> > On Feb 5, 4:28 pm, Shay Banon \<[kim...@gmail.com](mailto:kim...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> > 
> > > percolator support boolean query / filters. Gist a full recreation and we can have a look at it ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)).
> 
> > > On Friday, February 3, 2012 at 6:37 AM, vibin dhas wrote:
> > > 
> > > > Hi,
> 
> > > > After understanding the basic concepts of Percolator, I started adding  
> > > > query as well as filter to a percolator, but it seems like, somewhere  
> > > > went wrong and the percolator is considering only the query while  
> > > > pulling the results and filters are getting ignored.
> 
> > > > I am not sure if Percolator supports filter along with query. Then I  
> > > > tried adding those filter conditions as multiple queries and that too  
> > > > failed. So, how can I achieve adding a complete search(with query and  
> > > > filter) in Percolator?
> 
> > > > Below is the code snippet I am using for this. Please let me know if I  
> > > > am wrong any where
> 
> > > > BoolQueryBuilder qb = new BoolQueryBuilder();  
> > > > qb.must(termQuery("field1","value"));  
> > > > qb.must(termQuery("field2","value"));  
> > > > client.prepareIndex("\_percolator", "alert", "id1")  
> > > > .setSource(XContentFactory.jsonBuilder().startObject().field("query",  
> > > > qb).endObject())  
> > > > .setRefresh(true).setRouting(index)  
> > > > .execute().actionGet();
> 
> > > > Cheers,
> > > > 
> > > > - Vibin

---

<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, 3:40am UTC](https://discuss.elastic.co/t/adding-filters-to-percolator-query/6579/6 "2017-07-06T03:40:10Z")

</div>


