Continuing the discussion from Never ending story: how to check and remove empty fields, arrays etc:
There's no simple way to (recursively) get all field names in an event, but one can do this:
filter {
ruby {
init => "
def remove_empty_fields(event)
_find_empty_fields(event.to_hash) { |path| event.remove('[' + path.join('][') + ']') }
end
def _find_empty_fields(event, path = [], &blk)
event.each do |k, v|
curpath = path + [k]
case v
when nil
yield curpath
when ''
yield curpath
when []
yield curpath
when {}
yield curpath
when Hash
_find_empty_fields(v, curpath, &blk)
end
end
end
"
code => "remove_empty_fields(event)"
}
}