# Range query in percolate not working

**URL:** https://discuss.elastic.co/t/range-query-in-percolate-not-working/7476
**Category:** Elasticsearch
**Created:** [April 26, 2012, 2:19pm UTC](https://discuss.elastic.co/t/range-query-in-percolate-not-working/7476 "2012-04-26T14:19:44Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![jschelle\_2](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jschelle\_2](https://discuss.elastic.co/u/jschelle_2)
#### Post date: [April 26, 2012, 2:19pm UTC](https://discuss.elastic.co/t/range-query-in-percolate-not-working/7476/1 "2012-04-26T14:19:44Z")

</div>

I'm trying to use the Percolate features. It seems to work fine for text,  
but when I try a range query with numeric values I get odd behavior. Every  
document seems to have the same query and it shouldn't! Can anyone see  
what I'm doing wrong?

//create index  
$ curl -XPUT localhost:9200/jperctest3  
{"ok":true,"acknowledged":true}

//insert a bunch of queries to the percolator  
$ curl -XPOST '[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)' -d  
'{"query":{"range":{"hits":{"from":50,"to":75,"include\_lower":true,"include\_upper":true}}}}'  
{"ok":true,"\_index":"\_percolator","\_type":"jperctest3","\_id":"QMQ3mo\_8RSWidcFOgbdxGg","\_version":1}

$ curl -XPOST '[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)' -d  
'{"query":{"range":{"hits":{"from":50,"to":60,"include\_lower":true,"include\_upper":true}}}}'  
{"ok":true,"\_index":"\_percolator","\_type":"jperctest3","\_id":"omenhMF5QDaD6LGORa38wg","\_version":1}

$ curl -XPOST '[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)' -d  
'{"query":{"range":{"hits":{"from":5,"to":20,"include\_lower":true,"include\_upper":true}}}}'  
{"ok":true,"\_index":"\_percolator","\_type":"jperctest3","\_id":"mhsSnSNgQR6fGysbCHNAkw","\_version":1}

$ curl -XPOST '[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)' -d  
'{"query":{"range":{"hits":{"from":1,"to":9,"include\_lower":true,"include\_upper":true}}}}'  
{"ok":true,"\_index":"\_percolator","\_type":"jperctest3","\_id":"WopYvt70TqOkd-9CngZivQ","\_version":1}

//now add documents  
$ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
'{"doc":{"hits":30}}'  
{"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}

$ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
'{"doc":{"hits":4}}'  
{"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}

$ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
'{"doc":{"hits":0}}'  
{"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}

$ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
'{"doc":{"hits":-1}}'  
{"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}

$ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
'{"doc":{"hits":-10000000}}'  
{"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}

---

<div class="post-metadata">

### Author: ![jschelle\_2](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jschelle\_2](https://discuss.elastic.co/u/jschelle_2)
#### Post date: [April 26, 2012, 3:35pm UTC](https://discuss.elastic.co/t/range-query-in-percolate-not-working/7476/2 "2012-04-26T15:35:23Z")

</div>

Just to add: basically any value of "hits" that I percolate the return says  
is matches the 1-9 range above.

On Thursday, April 26, 2012 10:19:44 AM UTC-4, jschelle wrote:

> I'm trying to use the Percolate features. It seems to work fine for text,  
> but when I try a range query with numeric values I get odd behavior. Every  
> document seems to have the same query and it shouldn't! Can anyone see  
> what I'm doing wrong?
> 
> //create index  
> $ curl -XPUT localhost:9200/jperctest3  
> {"ok":true,"acknowledged":true}
> 
> //insert a bunch of queries to the percolator  
> $ curl -XPOST '[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)' -d  
> '{"query":{"range":{"hits":{"from":50,"to":75,"include\_lower":true,"include\_upper":true}}}}'
> 
> {"ok":true,"\_index":"\_percolator","\_type":"jperctest3","\_id":"QMQ3mo\_8RSWidcFOgbdxGg","\_version":1}
> 
> $ curl -XPOST '[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)' -d  
> '{"query":{"range":{"hits":{"from":50,"to":60,"include\_lower":true,"include\_upper":true}}}}'
> 
> {"ok":true,"\_index":"\_percolator","\_type":"jperctest3","\_id":"omenhMF5QDaD6LGORa38wg","\_version":1}
> 
> $ curl -XPOST '[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)' -d  
> '{"query":{"range":{"hits":{"from":5,"to":20,"include\_lower":true,"include\_upper":true}}}}'
> 
> {"ok":true,"\_index":"\_percolator","\_type":"jperctest3","\_id":"mhsSnSNgQR6fGysbCHNAkw","\_version":1}
> 
> $ curl -XPOST '[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)' -d  
> '{"query":{"range":{"hits":{"from":1,"to":9,"include\_lower":true,"include\_upper":true}}}}'
> 
> {"ok":true,"\_index":"\_percolator","\_type":"jperctest3","\_id":"WopYvt70TqOkd-9CngZivQ","\_version":1}
> 
> //now add documents  
> $ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
> '{"doc":{"hits":30}}'  
> {"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}
> 
> $ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
> '{"doc":{"hits":4}}'  
> {"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}
> 
> $ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
> '{"doc":{"hits":0}}'  
> {"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}
> 
> $ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
> '{"doc":{"hits":-1}}'  
> {"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}
> 
> $ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
> '{"doc":{"hits":-10000000}}'  
> {"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}

On Thursday, April 26, 2012 10:19:44 AM UTC-4, jschelle wrote:

> I'm trying to use the Percolate features. It seems to work fine for text,  
> but when I try a range query with numeric values I get odd behavior. Every  
> document seems to have the same query and it shouldn't! Can anyone see  
> what I'm doing wrong?
> 
> //create index  
> $ curl -XPUT localhost:9200/jperctest3  
> {"ok":true,"acknowledged":true}
> 
> //insert a bunch of queries to the percolator  
> $ curl -XPOST '[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)' -d  
> '{"query":{"range":{"hits":{"from":50,"to":75,"include\_lower":true,"include\_upper":true}}}}'
> 
> {"ok":true,"\_index":"\_percolator","\_type":"jperctest3","\_id":"QMQ3mo\_8RSWidcFOgbdxGg","\_version":1}
> 
> $ curl -XPOST '[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)' -d  
> '{"query":{"range":{"hits":{"from":50,"to":60,"include\_lower":true,"include\_upper":true}}}}'
> 
> {"ok":true,"\_index":"\_percolator","\_type":"jperctest3","\_id":"omenhMF5QDaD6LGORa38wg","\_version":1}
> 
> $ curl -XPOST '[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)' -d  
> '{"query":{"range":{"hits":{"from":5,"to":20,"include\_lower":true,"include\_upper":true}}}}'
> 
> {"ok":true,"\_index":"\_percolator","\_type":"jperctest3","\_id":"mhsSnSNgQR6fGysbCHNAkw","\_version":1}
> 
> $ curl -XPOST '[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)' -d  
> '{"query":{"range":{"hits":{"from":1,"to":9,"include\_lower":true,"include\_upper":true}}}}'
> 
> {"ok":true,"\_index":"\_percolator","\_type":"jperctest3","\_id":"WopYvt70TqOkd-9CngZivQ","\_version":1}
> 
> //now add documents  
> $ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
> '{"doc":{"hits":30}}'  
> {"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}
> 
> $ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
> '{"doc":{"hits":4}}'  
> {"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}
> 
> $ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
> '{"doc":{"hits":0}}'  
> {"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}
> 
> $ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
> '{"doc":{"hits":-1}}'  
> {"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}
> 
> $ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
> '{"doc":{"hits":-10000000}}'  
> {"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}

---

<div class="post-metadata">

### Author: ![jschelle\_2](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jschelle\_2](https://discuss.elastic.co/u/jschelle_2)
#### Post date: [April 26, 2012, 4:00pm UTC](https://discuss.elastic.co/t/range-query-in-percolate-not-working/7476/3 "2012-04-26T16:00:33Z")

</div>

I figured this out, but thought I'd post it so someone else can find it  
later. Basically I was relying on the automapper (not explicitly defining  
the fields in my index). Apparently that doesn't always work. I added the  
line below right after I create the index and now it works perfectly.

curl -XPUT '[http://localhost:9200/jperctest5/site/\_mapping](http://localhost:9200/jperctest5/site/_mapping)' -d  
'{"site":{"properties":{"hits":{"type":"integer"},"content":{"type":"string"},"site":{"type":"string"}  
}}}'

On Thursday, April 26, 2012 10:19:44 AM UTC-4, jschelle wrote:

> I'm trying to use the Percolate features. It seems to work fine for text,  
> but when I try a range query with numeric values I get odd behavior. Every  
> document seems to have the same query and it shouldn't! Can anyone see  
> what I'm doing wrong?
> 
> //create index  
> $ curl -XPUT localhost:9200/jperctest3  
> {"ok":true,"acknowledged":true}
> 
> //insert a bunch of queries to the percolator  
> $ curl -XPOST '[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)' -d  
> '{"query":{"range":{"hits":{"from":50,"to":75,"include\_lower":true,"include\_upper":true}}}}'
> 
> {"ok":true,"\_index":"\_percolator","\_type":"jperctest3","\_id":"QMQ3mo\_8RSWidcFOgbdxGg","\_version":1}
> 
> $ curl -XPOST '[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)' -d  
> '{"query":{"range":{"hits":{"from":50,"to":60,"include\_lower":true,"include\_upper":true}}}}'
> 
> {"ok":true,"\_index":"\_percolator","\_type":"jperctest3","\_id":"omenhMF5QDaD6LGORa38wg","\_version":1}
> 
> $ curl -XPOST '[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)' -d  
> '{"query":{"range":{"hits":{"from":5,"to":20,"include\_lower":true,"include\_upper":true}}}}'
> 
> {"ok":true,"\_index":"\_percolator","\_type":"jperctest3","\_id":"mhsSnSNgQR6fGysbCHNAkw","\_version":1}
> 
> $ curl -XPOST '[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)' -d  
> '{"query":{"range":{"hits":{"from":1,"to":9,"include\_lower":true,"include\_upper":true}}}}'
> 
> {"ok":true,"\_index":"\_percolator","\_type":"jperctest3","\_id":"WopYvt70TqOkd-9CngZivQ","\_version":1}
> 
> //now add documents  
> $ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
> '{"doc":{"hits":30}}'  
> {"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}
> 
> $ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
> '{"doc":{"hits":4}}'  
> {"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}
> 
> $ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
> '{"doc":{"hits":0}}'  
> {"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}
> 
> $ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
> '{"doc":{"hits":-1}}'  
> {"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}
> 
> $ curl -XGET localhost:9200/jperctest3/site/\_percolate -d  
> '{"doc":{"hits":-10000000}}'  
> {"ok":true,"matches":["WopYvt70TqOkd-9CngZivQ"]}

---

<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: [April 29, 2012, 4:22pm UTC](https://discuss.elastic.co/t/range-query-in-percolate-not-working/7476/4 "2012-04-29T16:22:54Z")

</div>

Heya,

Yea, because the mapping is not there for the field when you register the  
percolator query (and no document was indexed to derive the mapping for),  
the queries were registered as simple "string" ranges. Thanks for following  
this up with your solution.

-shay.banon

On Thu, Apr 26, 2012 at 7:00 PM, jschelle [jason.scheller@gmail.com](mailto:jason.scheller@gmail.com) wrote:

> I figured this out, but thought I'd post it so someone else can find it  
> later. Basically I was relying on the automapper (not explicitly defining  
> the fields in my index). Apparently that doesn't always work. I added the  
> line below right after I create the index and now it works perfectly.
> 
> curl -XPUT '[http://localhost:9200/jperctest5/site/\_mapping](http://localhost:9200/jperctest5/site/_mapping)' -d  
> '{"site":{"properties":{"hits":{"type":"integer"},"content":{"type":"string"},"site":{"type":"string"}  
> }}}'
> 
> On Thursday, April 26, 2012 10:19:44 AM UTC-4, jschelle wrote:
> 
> > I'm trying to use the Percolate features. It seems to work fine for  
> > text, but when I try a range query with numeric values I get odd behavior.  
> > Every document seems to have the same query and it shouldn't! Can anyone  
> > see what I'm doing wrong?
> > 
> > //create index  
> > $ curl -XPUT localhost:9200/jperctest3  
> > {"ok":true,"acknowledged":\*\*true}
> > 
> > //insert a bunch of queries to the percolator  
> > $ curl -XPOST '[http://localhost:9200/\_\*\*percolator/jperctest3/](http://localhost:9200/_**percolator/jperctest3/)[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)'  
> > -d '{"query":{"range":{"hits":{" **from":50,"to":75,"include\_**  
> > lower":true,"include\_upper":\*\*true}}}}'  
> > {"ok":true,"_index":"_\*\*percolator","\_type":"\*\*jperctest3","_id":"QMQ3mo_  
> > \*\*8RSWidcFOgbdxGg","\_version":1}
> > 
> > $ curl -XPOST '[http://localhost:9200/\_\*\*percolator/jperctest3/](http://localhost:9200/_**percolator/jperctest3/)[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)'  
> > -d '{"query":{"range":{"hits":{" **from":50,"to":60,"include\_**  
> > lower":true,"include\_upper":\*\*true}}}}'  
> > {"ok":true,"_index":"_\*\*percolator","_type":" **jperctest3","\_id":"**  
> > omenhMF5QDaD6LGORa38wg","_\*\*version":1}
> > 
> > $ curl -XPOST '[http://localhost:9200/\_\*\*percolator/jperctest3/](http://localhost:9200/_**percolator/jperctest3/)[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)'  
> > -d '{"query":{"range":{"hits":{" **from":5,"to":20,"include\_**  
> > lower":true,"include\_upper":\*\*true}}}}'  
> > {"ok":true,"_index":"_\*\*percolator","_type":" **jperctest3","\_id":"**  
> > mhsSnSNgQR6fGysbCHNAkw","_\*\*version":1}
> > 
> > $ curl -XPOST '[http://localhost:9200/\_\*\*percolator/jperctest3/](http://localhost:9200/_**percolator/jperctest3/)[http://localhost:9200/\_percolator/jperctest3/](http://localhost:9200/_percolator/jperctest3/)'  
> > -d '{"query":{"range":{"hits":{" **from":1,"to":9,"include\_lower"**  
> > :true,"include\_upper":true}}}}\*\*'  
> > {"ok":true,"_index":"_\*\*percolator","_type":" **jperctest3","\_id":"**  
> > WopYvt70TqOkd-9CngZivQ","_\*\*version":1}
> > 
> > //now add documents  
> > $ curl -XGET localhost:9200/jperctest3/\*\*site/\_percolate -d  
> > '{"doc":{"hits":30}}'  
> > {"ok":true,"matches":["\*\*WopYvt70TqOkd-9CngZivQ"]}
> > 
> > $ curl -XGET localhost:9200/jperctest3/\*\*site/\_percolate -d  
> > '{"doc":{"hits":4}}'  
> > {"ok":true,"matches":["\*\*WopYvt70TqOkd-9CngZivQ"]}
> > 
> > $ curl -XGET localhost:9200/jperctest3/\*\*site/\_percolate -d  
> > '{"doc":{"hits":0}}'  
> > {"ok":true,"matches":["\*\*WopYvt70TqOkd-9CngZivQ"]}
> > 
> > $ curl -XGET localhost:9200/jperctest3/\*\*site/\_percolate -d  
> > '{"doc":{"hits":-1}}'  
> > {"ok":true,"matches":["\*\*WopYvt70TqOkd-9CngZivQ"]}
> > 
> > $ curl -XGET localhost:9200/jperctest3/\*\*site/\_percolate -d  
> > '{"doc":{"hits":-10000000}}'  
> > {"ok":true,"matches":["\*\*WopYvt70TqOkd-9CngZivQ"]}

---

<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:30am UTC](https://discuss.elastic.co/t/range-query-in-percolate-not-working/7476/5 "2017-07-06T03:30:42Z")

</div>


