There is a field in log file, which contains IP address or empty string if IP address is not available.
Elasticsearch index has mapping, that maps "ip" type to this field. When field value is empty string, logstash can not save data to index:
[WARN ][logstash.outputs.elasticsearch] Could not index event to Elasticsearch
...
"error"=>{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse [doc.ip]", "caused_by"=>{"type"=>"illegal_argument_exception", "reason"=>"'' is not an IP string literal."}}}}}
To fix this, I need to convert empty string to null with logstash. This doesn't work:
if [doc][ip] == "" {
mutate {
replace => { "[doc][ip]" => null }
}
}
Because it converts value to string "null". "nil" doesn't work either.
What is correct syntax to convert field to null value?