-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Runtime field doesn't work correctly with range query when emitted value is 0.0 #71786
Comments
Because of the excluding the upper bound 0.0 the query is translated to an "field1:[-Infinity TO -0.0]" query. The "-0.0" upper value is included because its the next smallest value below 0.0 for the double type. While this is respected on the regular "double" field, the impelentation in DoubleScriptFieldRangeQuery uses a simple Java double comparison (i.e. a <=b) where apparently -0.0 == 0.0. Fortunately we can switch to Double.compare that seems to handle this case correctly. I'll open a PR shortly. |
DoubleScriptFieldRangeQuery which is used on runtime fields of type "double" currently uses simple double type comparison for checking its upper and lower bounds. Unfortunately it seems that -0.0 == 0.0, but when we want to exclude a 0.0 bound via "lt" the generated range query uses -0.0 as its upper bound which erroneously includes the 0.0 value. We can use `Double.compare` instead which seems to handle this edge case well. Closes elastic#71786
Pinging @elastic/es-search (Team:Search) |
DoubleScriptFieldRangeQuery which is used on runtime fields of type "double" currently uses simple double type comparison for checking its upper and lower bounds. Unfortunately it seems that -0.0 == 0.0, but when we want to exclude a 0.0 bound via "lt" the generated range query uses -0.0 as its upper bound which erroneously includes the 0.0 value. We can use `Double.compare` instead which seems to handle this edge case well. Closes #71786
DoubleScriptFieldRangeQuery which is used on runtime fields of type "double" currently uses simple double type comparison for checking its upper and lower bounds. Unfortunately it seems that -0.0 == 0.0, but when we want to exclude a 0.0 bound via "lt" the generated range query uses -0.0 as its upper bound which erroneously includes the 0.0 value. We can use `Double.compare` instead which seems to handle this edge case well. Closes #71786
DoubleScriptFieldRangeQuery which is used on runtime fields of type "double" currently uses simple double type comparison for checking its upper and lower bounds. Unfortunately it seems that -0.0 == 0.0, but when we want to exclude a 0.0 bound via "lt" the generated range query uses -0.0 as its upper bound which erroneously includes the 0.0 value. We can use `Double.compare` instead which seems to handle this edge case well. Closes #71786
Elasticsearch version (
bin/elasticsearch --version
): 7.12.0Plugins installed: []
JVM version (
java -version
): java version "16" 2021-03-16OS version (
uname -a
if on a Unix-like system): MacOS Catalina, Version 10.15.7Description of the problem including expected versus actual behavior:
When emitting the value 0.0 for a runtime time field of type double, a range query with lt (less equal) returns the wrong result.
Steps to reproduce:
Please include a minimal but complete recreation of the problem,
including (e.g.) index creation, mappings, settings, query etc. The easier
you make for us to reproduce it, the more likely that somebody will take the
time to look at it.
This range query returns the inserted document which is a wrong result. Please note that the range query condition is <0 - hence this query shouldn't return any documents. I noticed that this problem only occurs when emitting the value 0. Other values (e.g. 1.0, 2.0, 3.0...) work as expected.
The text was updated successfully, but these errors were encountered: