# Inconsistent results with range query

**URL:** <https://discuss.elastic.co/t/inconsistent-results-with-range-query/185723>\
**Category:** Elasticsearch\
**Created:** [June 13, 2019, 8:14pm UTC](https://discuss.elastic.co/t/inconsistent-results-with-range-query/185723 "2019-06-13T20:14:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oscar\_Sanchez\_Sanche](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/oscar_sanchez_sanche/32/36678_2.png) [@Oscar\_Sanchez\_Sanche](https://discuss.elastic.co/u/Oscar_Sanchez_Sanche)\
**Post date:** [June 13, 2019, 8:14pm UTC](https://discuss.elastic.co/t/inconsistent-results-with-range-query/185723/1 "2019-06-13T20:14:27Z")

</div>

Hi there, i have noticed the range query sometimes returns correct results and sometimes it doesn't.

For example, if i run this query:

```
{
"query": {
    "range" : {
        "meta._price.value" : {
            "gte" : 0,
            "lte" : 2,
            "boost" : 2.0
        }
    }
}

```

}

I get the correct response from elasticsearch:

{  
"took": 2,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 1,  
"max\_score": 2,  
"hits": [  
{  
"\_index": "osca1--localhost-post-1",  
"\_type": "post",  
"\_id": "62",  
"\_score": 2,  
"\_source": {  
"comment\_count": 0,  
"post\_title": "2 dollar product",  
"post\_author": {  
"raw": "admin",  
"id": 1,  
"login": "admin",  
"display\_name": "admin"  
},  
"menu\_order": 0,  
"attachments": ,  
"post\_excerpt": "",  
"post\_mime\_type": "",  
"post\_name": "2-dollar-product",  
"terms": {  
"product\_type": [  
{  
"parent": 0,  
"name": "simple",  
"term\_taxonomy\_id": 2,  
"term\_id": 2,  
"slug": "simple"  
}  
],  
},  
"term\_suggest": [  
"Uncategorized",  
"simple"  
],  
"post\_modified\_gmt": "2019-06-13 19:51:05",  
"comment\_status": "open",  
"post\_parent": 0,  
"post\_content": "",  
"ping\_status": "closed",  
"post\_id": 62,  
"post\_date": "2019-06-13 19:51:05",  
"meta": {  
"\_downloadable": [  
{  
"date": "1971-01-01",  
"datetime": "1971-01-01 00:00:01",  
"boolean": false,  
"raw": "no",  
"time": "00:00:01",  
"value": "no"  
}  
],  
"\_stock\_status": [  
{  
"date": "1971-01-01",  
"datetime": "1971-01-01 00:00:01",  
"boolean": false,  
"raw": "instock",  
"time": "00:00:01",  
"value": "instock"  
}  
],  
"\_product\_version": [  
{  
"date": "2019-06-13",  
"datetime": "2019-06-13 03:06:04",  
"boolean": false,  
"raw": "3.6.4",  
"time": "03:06:04",  
"value": "3.6.4"  
}  
],  
"\_regular\_price": [  
{  
"date": "1971-01-01",  
"datetime": "1971-01-01 00:00:01",  
"boolean": false,  
"double": 2,  
"raw": "2",  
"time": "00:00:01",  
"value": "2",  
"long": 2  
}  
],  
"\_tax\_class": [  
{  
"date": "1971-01-01",  
"datetime": "1971-01-01 00:00:01",  
"boolean": false,  
"raw": "",  
"time": "00:00:01",  
"value": ""  
}  
],  
"\_manage\_stock": [  
{  
"date": "1971-01-01",  
"datetime": "1971-01-01 00:00:01",  
"boolean": false,  
"raw": "no",  
"time": "00:00:01",  
"value": "no"  
}  
],  
"\_stock": [  
{  
"boolean": false,  
"raw": null,  
"value": null  
}  
],  
"\_virtual": [  
{  
"date": "1971-01-01",  
"datetime": "1971-01-01 00:00:01",  
"boolean": false,  
"raw": "no",  
"time": "00:00:01",  
"value": "no"  
}  
],  
"\_price": [  
{  
"date": "1971-01-01",  
"datetime": "1971-01-01 00:00:01",  
"boolean": false,  
"double": 2,  
"raw": "2",  
"time": "00:00:01",  
"value": "2",  
"long": 2  
}  
],  
}  
]  
},  
}  
}  
]  
}  
}

But if I amp the number in the range between 10-19 lte :

```
{
"query": {
    "range" : {
        "meta._price.value" : {
            "gte" : 0,
            "lte" : 15,
            "boost" : 2.0
        }
    }
}

```

}

This returns 0 results

Query starts working correctly again from 20 and so on, at least at first glance. Did I understand something wrong here about the query? Any advice is greatly appreciated.

---

<div class="post-metadata">

**Author:** ![gbrown](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gbrown/32/34482_2.png) [@gbrown](https://discuss.elastic.co/u/gbrown)\
**Post date:** [June 13, 2019, 10:03pm UTC](https://discuss.elastic.co/t/inconsistent-results-with-range-query/185723/2 "2019-06-13T22:03:54Z")

</div>

Check the mapping for this index. It looks like `meta._price.value` in the document that's returned is a string (that is, it's `"2"` as opposed to `2`), so it may be mapped as a non-numeric field (`text` or `keyword`).

If it's mapped as non-numeric field, then the range will be treated as string range, which work like an alphabetical/alphanumeric sort. For example, `"a" < "b" < "ba" < "c"` and `"1" < "2" < "20" < "3"`.

---

<div class="post-metadata">

**Author:** ![Oscar\_Sanchez\_Sanche](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/oscar_sanchez_sanche/32/36678_2.png) [@Oscar\_Sanchez\_Sanche](https://discuss.elastic.co/u/Oscar_Sanchez_Sanche)\
**Post date:** [June 22, 2019, 7:07pm UTC](https://discuss.elastic.co/t/inconsistent-results-with-range-query/185723/3 "2019-06-22T19:07:33Z")

</div>

Thanks @gbrown, it was indeed a problem with mappings.

---

<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 20, 2019, 7:07pm UTC](https://discuss.elastic.co/t/inconsistent-results-with-range-query/185723/4 "2019-07-20T19:07:34Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
