# Float value rendered incorrectly by elastic API

**URL:** <https://discuss.elastic.co/t/float-value-rendered-incorrectly-by-elastic-api/373180>\
**Category:** Elasticsearch\
**Created:** [January 14, 2025, 1:22pm UTC](https://discuss.elastic.co/t/float-value-rendered-incorrectly-by-elastic-api/373180 "2025-01-14T13:22:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eeijlar](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@eeijlar](https://discuss.elastic.co/u/eeijlar)\
**Post date:** [January 14, 2025, 1:22pm UTC](https://discuss.elastic.co/t/float-value-rendered-incorrectly-by-elastic-api/373180/1 "2025-01-14T13:22:47Z")

</div>

I have an index template which defines the data type for the field `liableban` as follows:

```
"liableBan": {
  "meta": {
    "entity": "usageCharacteristic.liableBan"
  },
  "null_value": 0,
  "store": true,
  "type": "long"
}

```

If I check the value of this field in elastic, it is set as follows:

```auto
  "liableBan": [
    -7193973785499238000
  ],

```

If I query using `curl`, as follows:

```auto
response=$(curl -s --insecure -u "$ELASTIC_USER:$ELASTIC_PASSWORD" -X GET "$ELASTIC_URL/$INDEX/_search" -H 'Content-Type: application/json' -d '{
  "query": {
    "term": {
      "eventId": "'$EVENT_ID'"
    }
  }
}')

echo $response

```

It comes out as follows:

```auto
"liableBan":-7193973785499238559

```

The last three digits are different. If I pipe the result into `jq`, I get the correct value back:

```auto
     "liableBan": -7193973785499238000,

```

I am getting the same issue with the python elastic library where it is coming out as ...8559 instead of 8000

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [January 14, 2025, 1:40pm UTC](https://discuss.elastic.co/t/float-value-rendered-incorrectly-by-elastic-api/373180/2 "2025-01-14T13:40:09Z")

</div>

Seems like it, like in the issue [discussed in this thread](https://discuss.elastic.co/t/number-value-change-when-insert-11258999069452421/372598/1), could be a limitation around the numeric precision supported by JSON.

---

<div class="post-metadata">

**Author:** ![eeijlar](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@eeijlar](https://discuss.elastic.co/u/eeijlar)\
**Post date:** [January 15, 2025, 9:20am UTC](https://discuss.elastic.co/t/float-value-rendered-incorrectly-by-elastic-api/373180/3 "2025-01-15T09:20:48Z")

</div>

Thanks @Christian_Dahlqvist

The only workaround I could find in python was to just pass the response to jq. I tried many other suggestions from chatgpt 🙂

```auto
def call_jq(json_data):
    if isinstance(json_data, dict):
        json_data = json.dumps(json_data)

    try:
        result = subprocess.run(
            ["jq", "."],
            input=json_data,
            text=True,
            capture_output=True,
            check=True
        )
        return json.loads(result.stdout.strip())
    except subprocess.CalledProcessError as e:
        print(f"Error: {e.stderr}")
        return None
 

```

just call that method after getting the response back:

```auto
    response = es.search(index="_all", body=query)

    if response['hits']['hits']:
        es_data = response['hits']['hits'][0]['_source']
        fixed_data = call_jq(es_data)
        return clean_data(fixed_data)
    else:
        return None

```

---

<div class="post-metadata">

**Author:** ![RainTown](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raintown/32/140206_2.png) [@RainTown](https://discuss.elastic.co/u/RainTown)\
**Post date:** [January 15, 2025, 11:55pm UTC](https://discuss.elastic.co/t/float-value-rendered-incorrectly-by-elastic-api/373180/4 "2025-01-15T23:55:36Z")

</div>

Hi

Wild idea - just don’t store a floating point number of that absolute size into a float field. That’s a form of hidden technical debt you’re gifting to others down the line. Look to re-engineer a bit. I’ve no idea what liableBan corresponds to in real world sense, but I suspect you or your team might.

Patient: Doctor doctor, it hurts when I do this?

Doctor: Don’t do it then!
