Painless integer division

I am dividing two doc_counts from an aggregate to produce a percentage and compare it to a percentage. Does integer division in painless produce a float or another integer? I'm using the ctx.vars to get it into a log message to try to debug. Does the log message go to the elastic log or somewhere else?

"inline": "if ((ctx.payload.current_poll.aggregations.fandp.buckets.0.doc_count > 0) && (ctx.payload.current_poll.aggregations.fandp.buckets.1.doc_count > 0)) { ctx.vars.xx = (ctx.payload.current_poll.aggregations.fandp.buckets.1.doc_count / (ctx.payload.current_poll.aggregations.fandp.buckets.0.doc_count + ctx.payload.current_poll.aggregations.fandp.buckets.1.doc_count)); return > ctx.payload.week_poll.aggregations.avg_fail; } else { return false; }"

Found that painless does do int division (1/3 = 0). I'm not sure of the 'proper' way to convert but I used the python trick (1*1.0)/3 and I'm getting a decimal number.

this is indeed the correct 'trick'. Painless copies its division logic from java, where dividing two integers will result in an integer.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.