# Range filter acts strange

**URL:** <https://discuss.elastic.co/t/range-filter-acts-strange/17762>\
**Category:** Elasticsearch\
**Created:** [May 27, 2014, 7:55pm UTC](https://discuss.elastic.co/t/range-filter-acts-strange/17762 "2014-05-27T19:55:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan1](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@Dan1](https://discuss.elastic.co/u/Dan1)\
**Post date:** [May 27, 2014, 7:55pm UTC](https://discuss.elastic.co/t/range-filter-acts-strange/17762/1 "2014-05-27T19:55:03Z")

</div>

Hi People,

I use the following query to filter my data. Everything works great, untill  
I want to use a price-range filter.  
This range filter does not do exactly what I expect. I have a product in my  
collection with the price=10. When I set the filter to gte:1 - lte:11, it  
works, but gte:2 - lte:11 does not work. But the value price = 10 should  
match both ranges.

10 - 10 does also give no result, but 10 - 11 does..

Can anyone please help me?

{  
"query": {  
"match\_all": []  
},  
"filter": {  
"and": [  
{  
"term": {  
"representative": 1  
}  
},  
{  
"term": {  
"is\_gift": 0  
}  
},  
{  
"term": {  
"active": 1  
}  
},  
{  
"terms": {  
"website\_ids": [  
1  
],  
"execution": "and"  
}  
},  
{  
"terms": {  
"spec\_value\_ids": [  
"587",  
"584",  
"5828"  
],  
"execution": "or"  
}  
},  
{  
"terms": {  
"category\_ids": [  
"518"  
],  
"execution": "and"  
}  
},  
{

- "range": { "price": { "gte":  
2, "lte": 11 } }\*  
}  
]  
},  
"sort": {  
"price": {  
"order": "asc"  
}  
}  
}

--  
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/19155520-7683-48bf-82f1-0c31b419841f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/19155520-7683-48bf-82f1-0c31b419841f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Florentin\_Zorca](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@Florentin\_Zorca](https://discuss.elastic.co/u/Florentin_Zorca)\
**Post date:** [May 28, 2014, 7:03am UTC](https://discuss.elastic.co/t/range-filter-acts-strange/17762/2 "2014-05-28T07:03:40Z")

</div>

Hi,

maybe your price field is of type string, then for strings you have "1" \<  
"11" \< "2". Check your mapping.  
My experience with range filters is that they work correctly.

Kind regards,  
Florentin

Am Dienstag, 27. Mai 2014 21:55:03 UTC+2 schrieb Dan:

> Hi People,
> 
> I use the following query to filter my data. Everything works great,  
> untill I want to use a price-range filter.  
> This range filter does not do exactly what I expect. I have a product in  
> my collection with the price=10. When I set the filter to gte:1 - lte:11,  
> it works, but gte:2 - lte:11 does not work. But the value price = 10 should  
> match both ranges.
> 
> 10 - 10 does also give no result, but 10 - 11 does..
> 
> Can anyone please help me?
> 
> {  
> "query": {  
> "match\_all":   
> },  
> "filter": {  
> "and": [  
> {  
> "term": {  
> "representative": 1  
> }  
> },  
> {  
> "term": {  
> "is\_gift": 0  
> }  
> },  
> {  
> "term": {  
> "active": 1  
> }  
> },  
> {  
> "terms": {  
> "website\_ids": [  
> 1  
> ],  
> "execution": "and"  
> }  
> },  
> {  
> "terms": {  
> "spec\_value\_ids": [  
> "587",  
> "584",  
> "5828"  
> ],  
> "execution": "or"  
> }  
> },  
> {  
> "terms": {  
> "category\_ids": [  
> "518"  
> ],  
> "execution": "and"  
> }  
> },  
> {
> 
> - "range": { "price": { "gte":  
> 2, "lte": 11 } }\*  
> }  
> ]  
> },  
> "sort": {  
> "price": {  
> "order": "asc"  
> }  
> }  
> }

--  
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/92adc14b-1122-4de6-b774-a71a36fff3ef%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/92adc14b-1122-4de6-b774-a71a36fff3ef%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Dan1](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@Dan1](https://discuss.elastic.co/u/Dan1)\
**Post date:** [May 28, 2014, 8:44am UTC](https://discuss.elastic.co/t/range-filter-acts-strange/17762/3 "2014-05-28T08:44:00Z")

</div>

Yes, thats was the problem. I've added a mapping, thanks!

Op woensdag 28 mei 2014 09:03:40 UTC+2 schreef Florentin Zorca:

> Hi,
> 
> maybe your price field is of type string, then for strings you have "1" \<  
> "11" \< "2". Check your mapping.  
> My experience with range filters is that they work correctly.
> 
> Kind regards,  
> Florentin
> 
> Am Dienstag, 27. Mai 2014 21:55:03 UTC+2 schrieb Dan:
> 
> > Hi People,
> > 
> > I use the following query to filter my data. Everything works great,  
> > untill I want to use a price-range filter.  
> > This range filter does not do exactly what I expect. I have a product in  
> > my collection with the price=10. When I set the filter to gte:1 - lte:11,  
> > it works, but gte:2 - lte:11 does not work. But the value price = 10 should  
> > match both ranges.
> > 
> > 10 - 10 does also give no result, but 10 - 11 does..
> > 
> > Can anyone please help me?
> > 
> > {  
> > "query": {  
> > "match\_all":   
> > },  
> > "filter": {  
> > "and": [  
> > {  
> > "term": {  
> > "representative": 1  
> > }  
> > },  
> > {  
> > "term": {  
> > "is\_gift": 0  
> > }  
> > },  
> > {  
> > "term": {  
> > "active": 1  
> > }  
> > },  
> > {  
> > "terms": {  
> > "website\_ids": [  
> > 1  
> > ],  
> > "execution": "and"  
> > }  
> > },  
> > {  
> > "terms": {  
> > "spec\_value\_ids": [  
> > "587",  
> > "584",  
> > "5828"  
> > ],  
> > "execution": "or"  
> > }  
> > },  
> > {  
> > "terms": {  
> > "category\_ids": [  
> > "518"  
> > ],  
> > "execution": "and"  
> > }  
> > },  
> > {
> > 
> > - "range": { "price": { "gte":  
> > 2, "lte": 11 } }\*  
> > }  
> > ]  
> > },  
> > "sort": {  
> > "price": {  
> > "order": "asc"  
> > }  
> > }  
> > }

--  
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/b3138e46-054a-4e86-880f-bcf3c9c5e3a4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b3138e46-054a-4e86-880f-bcf3c9c5e3a4%40googlegroups.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:26am UTC](https://discuss.elastic.co/t/range-filter-acts-strange/17762/4 "2017-07-06T01:26:26Z")

</div>


