Inconsistent results with range query

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.

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