Is there any way to check existence of a field within a script, and return null/undefined instead of a value?
Let's say I have a simple groovy script that sums the value of two fields:
doc['field1'].value + doc['field2'].value
Then I run a Stats aggregation in ES and get the average
of the script values.
My question is how to handle sparse data, especially when both field1
and field2
are missing. I understand the script would return 0
in this case, which is not correct. The value is actually _missing_
and shouldn't be included in the average. Returning 0 throws the average way off.