-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Sum Aggregation On Nested Doc Not Handling Negative Numbers #9979
Comments
@martijnvg @jpountz any idea where things might be going wrong here? |
The exponent of the sum is suspicious (-321), it's typically what you would get when interpreting bits of a small long as a double. For instance |
I quickly tried to reproduce the issue with no success. Here is the script I used:
|
@natenash203 Could you let us know which elasticsearch version you are running and whether you rely on dynamic mappings? |
@jpountz Currently running 1.4.4. However, I am pretty sure I was running 1.4.0 when I initially created the index, set the mappings, and indexed the data. W/re to mapping, I use a mix of explicit and dynamic mappings. The field in question however, is mapped dynamically. Currently, the index is reporting it's mapped as a double. For reference, the range of possible values for the "v" field go from roughly -11,000,000,000.00 to 11,000,000,000.00 and as they are dollars, will include decimal places to the hundreds (i.e 12.34). Do you think I should explicitly map the "v" field to a float? Perhaps double, but isn't that not good for currency values? |
OK, then I probably know what happened:
This is unfortunately a know issue, see #8688 for more background.
Explicit mapping is certainly a good idea as it avoids running into #8688. Regarding the type of the field, a good option is usually to store the number of cents as a long in order to avoid floating-point rounding issues. 64 bits would be more than enough to store the range of values you are interested in. Closing as a duplicate of #8688 |
After looking at #8688, that looks right to me. When I initially indexed, my "v" values were sometimes floats and sometimes doubles. I index at about 1000 docs/sec so with 30 shards, it's entirely possible, one shard dynamically mapped a float and another mapped a double. I will reindex with an explicit mapping and go from there. Thanks much for the help. |
I have a an index with 30M documents, spread across 4 nodes, 30 shards, with 2 replicas each. Each document has a nested mapping type "a", representing a transaction log entry. Each transaction log entry has a positive or negative dollar value and a timestamp. When I attempt to bucket the nested objects using the date range and sum aggregations, the sum aggregation appears to break on transactions with both positive and negative numbers.
For example, consider the following query. I include a reverse nested agg to show that the nested objects are different than the output of the sum agg.
The following result is returned. Note the odd number in the DATEBUCKET_SUBTOTAL in FY2012 for "ASpecialPlace". This appears to only be an issue when the transaction log contains both negative and positive numbers. (Response slightly truncated...)
If I set a filter at the nested level to remove any nested "a" objects with a negative value, everything works fine. Note, this behavior is also apparent if using a stats agg instead of just a sum.
The text was updated successfully, but these errors were encountered: