Painless is basically Java, and your variables are all integers, this is why you are getting zero (it's only doing integer division): Painless integer division
Cast your variables to float before doing the division, then it should work like you expect.
Could you check whether you have a field formatter set on that field removing all things after the decimal point?
Also, please double check your script whether it's actually doing the right thing - when I'm looking at the script, count can only ever be 0 or 1 - is this really intended?
Your script won't do that calculation. Scripted fields are executed for each document separately, so you can't access aggregated data. In your script, count is set to 0 in the beginning, and bumped to 1 if MarketingCarrier and OperatingCarrier set. This will make count either 0 or 1 for this calculation:
Thanks for your input!
I thought count and af failures will all get calculated based at a time like for loop.
Our goal is to find the percentage of total failure count of AF w.r.t total count(based on 2 other properties which is marketing and operating carrier).
Is there a way we can achieve this.
When you are working with time based data, you can use TSVB to do this because it has a "math" aggregation which allows you to specify a formula executed on the aggregated data.
You can do calculations in scripted fields and use them in the data table, but you have to be aware these calculations happen for each document separately - there's no way around this. In the datatable visualization you can't do calculations in any another way.
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.