I thought I understood scaled float, and up until today they have worked as expected, but I indexed some new data and scaled_float fields got rounded in a way I can't explain.
Consider the below mapping - taken direct from the index in question:
"daily": {
"properties": {
"cost": {
"type": "scaled_float",
"ignore_malformed": false,
"scaling_factor": 6,
"coerce": true
},
"cost_per_kwh": {
"type": "scaled_float",
"ignore_malformed": false,
"scaling_factor": 4,
"coerce": true
},
"kwh": {
"type": "scaled_float",
"ignore_malformed": false,
"scaling_factor": 3,
"coerce": true
}
}
}
Now consider the below document found in it:
{
"_source": {
"daily": {
"kwh": 10.197,
"cost": 4.45,
"cost_per_kwh": 0.436403
},
},
"fields": {
"daily.kwh": [
10.333333333333334
],
"daily.cost": [
4.5
],
"daily.cost_per_kwh": [
0.5
]
}
You can see the correct values in the _source
- this is what I expect to saved as a scaled_float, yet all three numbers are being rounded oddly.
Take for example cost - it has a scaling factor of 6 so I'd expect 6 decimal points of precision to be saved - yet the source value of 4.45
has been stored as 4.5
.
Then also consider kwh
, which not only has a similar rounding error, but has 15 decimal points of precision despite having a scaling factor of 3!
I find this most perplexing- how can it be?