Percolate not returning results as expected

567 Views Asked by At

We're trying to set up and use percolate, but we aren't quite getting results as expected.

First, I register a few queries:

curl -XPUT 'localhost:9200/index-234234/.percolator/query1' -d '{
    "query" : {
        "range" : {
            "price" : { "gte": 100 }
        }
    }
}'

curl -XPUT 'localhost:9200/index-234234/.percolator/query2' -d '{
    "query" : {
        "range" : {
            "price" : { "gte": 200 }
        }
    }
}'

And then, when I try to match it against 150, which should ideally match only query1, instead it matches both queries:

curl -XGET 'localhost:9200/index-234234/message/_percolate' -d '{
    "doc" : {
        "price" : 150
    }
}'

{"took":4,"_shards":{"total":5,"successful":5,"failed":0},"total":2,"matches":[{"_index":"index-234234","_id":"query1"},{"_index":"index-234234","_id":"query2"}]}

Any pointers as to why this is happening would be much appreciated.

2

There are 2 best solutions below

1
On BEST ANSWER

The problem is that you are registering your percolator queries prior to setting up the mappings for the document. The percolator has to register the query without a defined mapping and this can be an issue particularly for range queries.

You should start over again by deleting the index and then run this mapping command first:

curl -XPOST localhost:9200/index-234234 -d '{
 "mappings" : {
      "message" : {
        "properties" : {
          "price" : {
            "type" : "long"
          }
        }
      }
    }
}'

Then execute your previous commands (register the two percolator queries and then percolate one document) you will get the following correct response:

{"took":3,"_shards":{"total":5,"successful":5,"failed":0},"total":1,"matches":[{"_index":"index-234234","_id":"query1"}]}

You may find this discussion from a couple of years ago helpful:

http://grokbase.com/t/gg/elasticsearch/124x6hq4ev/range-query-in-percolate-not-working

0
On

Not a solution, but this works (without knowing why) for me:

  1. Register both percolator queries
  2. Do the _percolator request (returns your result: "total": 2)
  3. Register both percolator queries again (both are now in version 2)
  4. Do the _percolator request again (returns right result: "total": 1)