-
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
Dynamic Field Mapping and Templates using numeric_detection does not match documentation #30939
Comments
Pinging @elastic/es-search-aggs |
@jpountz could you confirm if this is a bug in the code or the documentation? |
The documentation is wrong indeed. I'll fix.
That part probably needs clarification though I'm not sure how to do it. Basically, the json parser assumes the wider datatype that is not a BigDecimal/BigInteger. So floating-point numbers will be detected as a
This feature has been asked already at #30939, but it has taken some time because most of the needs that were expressed initially couldn't be supported, such as aggregating big decimals. However there seems to be a number of people who seem interested in uint64 support and accept the fact that aggregations would work by dynamically converting them to doubles, which might incur some accuracy loss. |
Describe the feature: Bug in Dynamic field mapping of floating point numbers with
numeric_detection
enabled.Elasticsearch version (
bin/elasticsearch --version
): 6.2.2Plugins installed: []
JVM version (
java -version
): 1.8.0_66OS version (
uname -a
if on a Unix-like system): RHEL6Description of the problem including expected versus actual behavior:
According to the documentation on Dynamic field mapping, when
numeric_detection
is enabled passing a floating point number as astring
will map the field to adouble
.However, this actually results in the field being mapped as a
float
.In addition, the documentation on Dynamic templates indicates that only the following datatypes can be dynamically mapped using
match_mapping_type
:Therefore, based on the absence of the float datatype in that list and the fact that the floating point numbers are being dynamically mapped with a float datatype, it would seem that dynamically mapped floating point numbers cannot be mapped to a double datatype using
match_mapping_type
.There is a workaround using
match_mapping_type
. I verified dynamic templates will not allow a value offloat
for thematch_mapping_type
, but I found that using a dynamic template with amatch_mapping_type
ofdouble
will map the fields that would have been dynamically mapped asfloat
todouble
. See Steps to reproduce for an example of the workaround.*DISCLAIMER The following is a shameless plug for 64-bit Unsigned Integer support in Elasticsearch
The dynamic mapping to double is needed as there is no support for 64-bit unsigned integers in Elasticsearch, whereas the system publishing the data (a custom Elastic Beat written in Go) does support 64-bit unsigned integers. The Beat was coded to workaround the limitations of Elasticsearch by publishing the 64-bit unsigned integer values as strings with a trailing '.0', so they are dynamically mapped as doubles. Otherwise, calculations, including those done in aggregations, in Elasticsearch were generating inaccurate results (even with the understanding that certain precision loss would happen) due to overflows (precision loss is one thing, getting a negative result when it is not mathematically possible is another). I've only been working with the stack for a short time, but I appreciate the complexity, capabilities and power of it. However, it feels "hackish" to have to treat 64-bit unsigned integers (not an uncommon thing) as floating point numbers masquerading as strings to be able to dynamically map and store them in a way that can efficiently be used in calculations and aggregations.
Steps to reproduce:
start
andend
fields are dynamically mapped asfloat
WORKAROUND
double
todouble
]start
andend
fields are dynamically mapped asdouble
EPILOGUE
Just to illustrate the impact of the mapping using the following query:
float
double
NOTE: Results are the same even when using
BigDecimal
to do the calculations:Provide logs (if relevant):
The text was updated successfully, but these errors were encountered: