MichaelN
(Michael Naor)
August 16, 2018, 1:00pm
1
Hi all,
I am trying to make a % calculation based on two fields.
I made the following script:
if (doc['doc.contextMap.totalErrors.keyword'].value != null && doc['doc.contextMap.totalInput.keyword'].value != null) {
return (Integer.parseInt(doc['doc.contextMap.totalErrors.keyword'].value) / Integer.parseInt(doc['doc.contextMap.totalInput.keyword'].value)) * 100;
} else {
return -100;
}
The outcome is always 0. It pass the IF condition but the calculation is always 0.
Any suggestions on what I am doing wrong?
Thanks
a5a
(Archana )
August 16, 2018, 4:11pm
2
null
and 0
are different values. It may be that the doc['doc.contextMap.totalErrors.keyword'].value
is 0. Can you verify?
MichaelN
(Michael Naor)
August 17, 2018, 5:38pm
3
Hi,
There are a values in totalErrors. Now I am thinking about another problem, may be I need to cast it into float and not an integer. What should be the syntax to do it?
Thanks.
MichaelN
(Michael Naor)
August 17, 2018, 5:53pm
4
Indeed the problem was in casting to integer instead of float.
Here is the correct script that work for me
if (doc['doc.contextMap.totalErrors.keyword'].value != null && doc['doc.contextMap.totalInput.keyword'].value != null) {
return (Float.parseFloat(doc['doc.contextMap.totalErrors.keyword'].value) / Float.parseFloat(doc['doc.contextMap.totalInput.keyword'].value));
} else {
return -100;
}
system
(system)
Closed
September 14, 2018, 6:03pm
5
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.