# ES6 - range query on float in not exact

**URL:** <https://discuss.elastic.co/t/es6-range-query-on-float-in-not-exact/186740>\
**Category:** Elasticsearch\
**Created:** [June 20, 2019, 5:40pm UTC](https://discuss.elastic.co/t/es6-range-query-on-float-in-not-exact/186740 "2019-06-20T17:40:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![theonlyalterego](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theonlyalterego/32/62069_2.png) [@theonlyalterego](https://discuss.elastic.co/u/theonlyalterego)\
**Post date:** [June 20, 2019, 5:40pm UTC](https://discuss.elastic.co/t/es6-range-query-on-float-in-not-exact/186740/1 "2019-06-20T17:40:35Z")

</div>

My problem is when running the below range query against a float I am getting a value outside the range. specifically the value 518832000000 is greater than the "LTE" value of 518831999999.

MAPPING

```
  "birthDate": {
    "properties": {
      "value": {
        "type": "float"
      }
    }
  }

```

QUERY

```
GET test_person/_search
{
  "query": {
    "range": {
      "birthDate.value": {
        "gte": 518745600000,
        "lte": 518831999999
      }
    }
  },
  "_source": ["birthDate.value"]
}

```

RESULT

```
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 2,
    "successful": 2,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 1,
    "hits": [
      {
        "_index": "test_person",
        "_type": "person",
        "_id": "2117461",
        "_score": 1,
        "_source": {
          "birthDate": [
            {
              "value": 518832000000
            }
          ]
        }
      },
      {
        "_index": "test_person",
        "_type": "person",
        "_id": "8185131",
        "_score": 1,
        "_source": {
          "birthDate": [
            {
              "value": 518745600000
            }
          ]
        }
      }
    ]
  }
}

```

I can work around this if I change LTE to LT , and the input from 518831999999 to 518832000000 it works, but it's weird that the LTE is including something outside the range.

---

<div class="post-metadata">

**Author:** ![wangqinghuan](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wangqinghuan](https://discuss.elastic.co/u/wangqinghuan)\
**Post date:** [June 20, 2019, 6:51pm UTC](https://discuss.elastic.co/t/es6-range-query-on-float-in-not-exact/186740/2 "2019-06-20T18:51:36Z")

</div>

float has only 23 bits precision, so the number 518831999999 will be represented to 5188320 \* 10^5 equals 518832000000

---

<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 18, 2019, 6:51pm UTC](https://discuss.elastic.co/t/es6-range-query-on-float-in-not-exact/186740/3 "2019-07-18T18:51:37Z")

</div>

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