Scripted Field on blank or zero fields

Hello everyone,
I am new to Kabana and I am trying to create a scripted field using the following script:

(doc['account_chargeable_hours'].value) / ( doc['avail_hrs'].value - doc['hsv_hours'].value )

However it is possible some or all of the values to be zero or blank. How to solve such issue?

You could do something like this (untested)

if (doc.containsKey('account_chargeable_hours') && doc.containsKey('avail_hrs') && doc.containsKey('hsv_hours')) {
  return (doc['account_chargeable_hours'].value) / ( doc['avail_hrs'].value - doc['hsv_hours'].value )

Hi Tyler,

The problem is bigger. If I use the time series I can correctly build my chart however the scripted field calculation is leading to mathematical error which I demonstrate with the attached picture.
Is it possible with a scripted field to archive 0.49 instead of 0.55?

Thank you,

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