Kibana Scripted Fields aggregation

I am new to kibana and trying to create dashboard. I have 4 scripted fields which are calculating dollar savings for specific process due to automation. i am trying to get sum of these 4 scripted fields to show total savings due to process automation. I looked at documentation but unable to find way to achieve this. Some fields may have null value for certain record. i have tried following code but its not working.

i have tried to assign following code to new scripted field to get sum for 2 fields.

def field1_value = params['_source']['HR_COST_AV'];
def field2_value = params['_source']['Marketing_Cost_AV'];

if(field1_value != null) {
  if(field2_value != null) {
    return field1_value + field2_value;
  } else {
    return field1_value;
  }
} else {
  return field2_value;
}

Hi,

in elasticsearch document, there are no empty field. Those fields without any value just do not exist.
Therefore you have to check null before you access params['_source']['HR_COST_AV']

See "Missing fields" section of the below document. In addition, access a field using doc values should be preferreble for performance reason.

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