Trying to sum/stats of transaction amounts for given search criteria but sum/stats amount is getting rounded up/down in place of returning decimal 2 positions. Below is one transaction data. The transactionAmount field is float type. This mostly happens when bucket size is only 1.
Obviously using double is a solution. But @Manoj_Upadhyay has maybe not understood the problem?
Manoj: A float (in elasticsearch) is represented by 32 bits. This actually means the same 32 bit representation can represent a whole range of (real) numbers. In your case the bit representation of the exact number 9999994.74 is:
0 10010110 00110001001011001111011
The bit representation of exactly 9999995 is
0 10010110 00110001001011001111011
You will notice those bit representations are identical.
In fact all numbers from 9999994.51 to 9999995.49 will be stored as exactly that same bit pattern. And 9999995 is the number right in the middle of that "range".
If you need do something with the actual numbers (in many cases) this will be done with the bit representations, not the strings that you see in _source.
A double means the numbers are stored much more precisely, actually using 64 bits rather than just 32. So these are much more precise.
So any time you have numbers with more than around 6/7 digits, you should make sure to use the double data type to avoid issues like this.
Thanks for details. I am surprised why it happens mostly when bucket has "doc_count": 1, only one element , it works fine when bucket size is more than 1 .
Indices has too many documents ( around billion) then how I can easily re-index them.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.