I'd like to be able to return a 'null' from a scripted field defined in Kibana - e.g.,
my_scripted_field = doc['field_1'].value != 0 ? doc['field_2'].value : null
The idea is that if
field_1 doesn't exist (== 0 in Lucence expressions), then there is no value assigned to
my_scripted_field - as if the field doesn't exist in a document.
The ultimate use-case, is to be able to run a 'count distinct' (cardinality) aggregation on
my_scripted_field, but without it counting
0 as a distinct value (which would be the case if I allow the ternary operator to revert to default behaviour when == 0).
Is there any way to return a 'null' to get the desired behaviour with Lucene expressions, and if not, is this something I could achieve by enabling Groovy scripting?