Closed ferrency closed 6 years ago
For anybody looking to solve it. You can use multiple filters to solve it.
filter {
mutate {
convert => {
"fieldname" => "string"
}
}
}
filter {
mutate {
convert => {
"fieldname" => "boolean"
}
}
}
First the field is converted to string and then string can be easily converted to boolean.
Generally in case of fixing it - how about doing value.to_s?
See also related issue #47.
Summary
Using the mutate
convert
feature to convert non-string values to boolean does not work correctly.Should it?
If it should, I will provide a patch to make it work. If it should not, I can provide a documentation patch to reflect that conversion to boolean only works on string values.
Details of why it fails
See
convert_boolean
, here: https://github.com/logstash-plugins/logstash-filter-mutate/blob/master/lib/logstash/filters/mutate.rb#L303Method
convert_boolean
converts a value to boolean using regular expressions. Regular expressions won't match on an integer or float, so conversions from non-string field values do not work correctly. Also, theempty?
method is used to convert empty strings to false boolean values. Attempting to convert a non-string value to boolean results in an exception being thrown because theempty?
method doesn't exist in classFixNum
.Proposed patch
Alternately: Document that boolean conversions only work on strings, and that converting from a non-boolean value to boolean requires multiple
convert
steps (withstring
as an intermediate convertsion type).Thanks! Alan Ferrency