Description
openedon Feb 2, 2024
Elasticsearch Version
main
Installed Plugins
No response
Java Version
all
OS Version
all
Problem Description
For numerical field types, range queries fail if the bounds are out of range for the given data type, albeit not 100% consistently.
For an index with a half_float
or float
field, e.g. a "lte" : some_big_number
fails for any value larger than Float.MAX_VALUE
with a QueryShardException: supports only finite values, but got [Infinity]
.
The same is true for byte/short/integer fields if the value falls outside integer range, as well as for a term query "term": {"half_float_field": {"value": 1E300}}
.
Scaled floats seem to be okay with the full range of doubles.
The reason is that in the NumberFieldMapper, we try to parse the literal to a float if the query's field is a half_float/float (resp. to an integer if the field is a byte/short/int).
This is problematic for query languages, as it causes inconsistencies; e.g. in ESQL:
from some_idx
| eval half_float_field < double_field // this is okay
from some_idx
| where half_float_field < 1E300 // this results in a query shard exception
The same is true for SQL and EQL.
This is also inconsistent with runtime fields, which don't expose this behavior:
{
"runtime_mappings": {
"infinity": {
"type": "boolean",
"script": {
// the following is okay and returns true
"source": "emit(doc['sf'].value < (Double.valueOf(1).doubleValue() * Math.pow(10.0, 300)))"
}
}
},
"query": {
"match_all":{}
},
"fields":["infinity"],
"_source": false
}
Steps to Reproduce
PUT /testidx
{"mappings": {"properties": {"half_float_field": {"type": "half_float"}}
POST /testidx/_doc
{"half_float_field": 1.0}
POST /_search
{"query": {"range": {"half_float_field": {"lte": 1E300}}}}
Logs (if relevant)
No response