I have a watch that performs an average on a value. I would like to round it to two decimal places. For some reason when I put the script in to round the result is wrong, plus it doesn't even round. In the below code avt_tv comes out to 1114.873063170441 while avg_tv_round comes out to 560.9466266866567. What am I doing wrong?
So I figured out why one of my issues is happening. The avt_tv_round is dfferent because I have entries without the TESTVALUE field. According to the document I read on the avg aggreation missing values are supposed to be ignored but it seems that it is still counting those entries into the count for the avg divisor i.e. 3 of my 4 entries have TESTVALUE but after adding them together it divides by 4 instead of 3.
However scripting still means, that a script has to be executed for every document that is found, so just using this for rounding is highly inefficeent. Might be less resource intensive to just do this on the client side.
That circumvented the incorrect average problem but still the other problem the fact that it isn't rounding the result my updated code is below. Is there perhaps some setting I need to set in the elasticsearch.yml that I am unaware of? Or is it possible to round in the condition field(i tried but keep getting null back)
you could use NumberFormat/DecimalFormat to format, but this also converts to a string and you need to return a number here, because the average still needs to be calculated (which will be skewed as well).
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.