I need to search doc by filtering out the result of the steps below:

calculate (field1 + field2) * field3 -> result 1

round up the result of step (1) to 2 decimal points -> result 2

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.

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:
calculate (field1 + field2) * field3 -> result 1
round up the result of step (1) to 2 decimal points -> result 2
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.

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:

calculate (field1 + field2) * field3 -> result 1

round up the result of step (1) to 2 decimal points -> result 2

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.

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:
calculate (field1 + field2) * field3 -> result 1
round up the result of step (1) to 2 decimal points -> result 2
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.

Hi David,
It works with 100.0. It rounds up to 2 decimal points.

But, what if we need to round it up to 3 or x decimal points?

Rounding up a FLOAT, DOUBLE datatype to x decimal points is a common
business requirement. I wonder why there isn't any build-in function in
ElasticSearh to round up to x decimal points (I can't find it from
documentation).

Here is the outcome of my testing:

Math.round(7.8151100)/100 -> It returns 7.
round(7.8151) -> It returns 8.
Math.round(7.8151100)/100.0 -> It returns 7.82
Math.round(7.8151100.0)/100.0 -> It returns 7.82
Math.round(7.8151100.00)/100.00 -> It returns 7.82
Math.round(7.8151*100.000)/100.000 -> It returns 7.82

On Saturday, January 31, 2015 at 4:27:28 PM UTC+8, David Pilato wrote:

And this?

Math.round(doc['totals.tax'].value * 100.0)/100.0

David

Le 31 janv. 2015 à 09:19, Lee Chuen Ooi <leec...@gmail.com <javascript:>>
a écrit :

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

I need to search doc by filtering out the result of the steps below:

calculate (field1 + field2) * field3 -> result 1

round up the result of step (1) to 2 decimal points -> result 2

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.

Hi David,
It works with 100.0. It rounds up to 2 decimal points.

But, what if we need to round it up to 3 or x decimal points?

Rounding up a FLOAT, DOUBLE datatype to x decimal points is a common business requirement. I wonder why there isn't any build-in function in ElasticSearh to round up to x decimal points (I can't find it from documentation).

Here is the outcome of my testing:

Math.round(7.8151100)/100 -> It returns 7.
round(7.8151) -> It returns 8.
Math.round(7.8151100)/100.0 -> It returns 7.82
Math.round(7.8151100.0)/100.0 -> It returns 7.82
Math.round(7.8151100.00)/100.00 -> It returns 7.82
Math.round(7.8151*100.000)/100.000 -> It returns 7.82

On Saturday, January 31, 2015 at 4:27:28 PM UTC+8, David Pilato wrote:
And this?

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:
calculate (field1 + field2) * field3 -> result 1
round up the result of step (1) to 2 decimal points -> result 2
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.

On Monday, February 2, 2015 at 2:14:24 PM UTC+8, David Pilato wrote:

I guess something like this:

Math.round(7.8151*1000)/1000.0

--
David
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 2 févr. 2015 à 04:03, Lee Chuen Ooi <leec...@gmail.com <javascript:>>
a écrit :

Hi David,
It works with 100.0. It rounds up to 2 decimal points.

But, what if we need to round it up to 3 or x decimal points?

Rounding up a FLOAT, DOUBLE datatype to x decimal points is a common
business requirement. I wonder why there isn't any build-in function in
ElasticSearh to round up to x decimal points (I can't find it from
documentation).

Here is the outcome of my testing:

Math.round(7.8151100)/100 -> It returns 7.
round(7.8151) -> It returns 8.
Math.round(7.8151100)/100.0 -> It returns 7.82
Math.round(7.8151100.0)/100.0 -> It returns 7.82
Math.round(7.8151100.00)/100.00 -> It returns 7.82
Math.round(7.8151*100.000)/100.000 -> It returns 7.82

On Saturday, January 31, 2015 at 4:27:28 PM UTC+8, David Pilato wrote:

I need to search doc by filtering out the result of the steps below:

calculate (field1 + field2) * field3 -> result 1

round up the result of step (1) to 2 decimal points -> result 2

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.

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.