Adding filters to percolator query


(vibin) #1

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

(Shay Banon) #2

percolator support boolean query / filters. Gist a full recreation and we can have a look at it (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

(vibin) #3

sure, the gist is here...

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 wrote:

percolator support boolean query / filters. Gist a full recreation and we can have a look at it (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

(Shay Banon) #4

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

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 (http://gmail.com)> wrote:

percolator support boolean query / filters. Gist a full recreation and we can have a look at it (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

(vibin) #5

Its working now.

Thanks for your help with this, Shay.

-Vibin

On Feb 7, 11:49 pm, Shay Banon 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...

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 (http://gmail.com)> wrote:

percolator support boolean query / filters. Gist a full recreation and we can have a look at it (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

(system) #6