Hi,
It doesn't work. I tried before posting this thread. :-(

Here is what I use:

 "script" : "Math.round(doc['totals.tax'].value * 100)/100"

The result is an integer.




On Saturday, January 31, 2015 at 3:00:19 PM UTC+8, David Pilato wrote:
>
> Is this not working? Found it on stack over flow.
>
> Math.round(x * 100) / 100
>
>
>
> David
>
> Le 31 janv. 2015 à 04:06, Lee Chuen Ooi <leec...@gmail.com <javascript:>> 
> a écrit :
>
> Hi,
>
> Each doc has :
>
>    - field1  float datatype. For e.g., 99.9999
>    - field2  float datatype. For e.g., 7.991
>    - field3  float datatype. For eg.,  7.5007500800
>    - field4  float with 2 decimal points. For e.g. 8.10
>
>
> I need to search doc by filtering out the result of the steps below:
>
>    1. calculate (field1 + field2) * field3  -> result 1 
>    2. round up the result of step (1) to 2 decimal points -> result 2
>    3. If result of step (2) <> field4, return the doc in the search result
>
>
> I use "script" to achieve this. But, based on the documentation, there is 
> limited groovy build in function available. There is no sum function. I 
> need to use field1 * field3 + field2 * field3 to get result 1 as a 
> workaround.
>
> I am stuck at Step 2. I am not able to round up the result of (field1 + 
> field2) * field3 to 2 decimal point. How can it be done? Pls suggest.
>
> If you have a better way to get it done, other than using "script", pls 
> suggest too.
>
> Thanks.
>
>
>
>  
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "elasticsearch" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to elasticsearc...@googlegroups.com <javascript:>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/elasticsearch/575e72be-d273-4f85-988f-6e280f9937f6%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/elasticsearch/575e72be-d273-4f85-988f-6e280f9937f6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elasticsearch+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/a1a89ae8-0bac-461a-844b-7e015790bb04%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to