ES6 - range query on float in not exact

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.

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

3 Likes

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