diff --git a/lib/logstash/filters/mutate.rb b/lib/logstash/filters/mutate.rb index b0693a4..8a6a78a 100644 --- a/lib/logstash/filters/mutate.rb +++ b/lib/logstash/filters/mutate.rb @@ -508,10 +508,9 @@ def merge(event) @merge.each do |dest_field, added_fields| # When multiple calls, added_field is an array - dest_field_value = event.get(dest_field) - Array(added_fields).each do |added_field| added_field_value = event.get(added_field) + dest_field_value = event.get(dest_field) if dest_field_value.is_a?(Hash) ^ added_field_value.is_a?(Hash) @logger.error("Not possible to merge an array and a hash: ", :dest_field => dest_field, :added_field => added_field ) diff --git a/spec/filters/mutate_spec.rb b/spec/filters/mutate_spec.rb index 31b32fb..3888a2c 100644 --- a/spec/filters/mutate_spec.rb +++ b/spec/filters/mutate_spec.rb @@ -1079,6 +1079,21 @@ def pattern_path(path) expect(subject.get("foo")).to eq "bar" end end + + describe "merge multiple fields into string field" do + config ' + filter { + mutate { + merge => [ "list", [ "foo", "spam" ] ] + } + }' + + sample("foo" => "bar", "spam" => "ham", "list" => "baz") do + expect(subject.get("list")).to eq ["baz", "bar", "ham"] + expect(subject.get("foo")).to eq "bar" + expect(subject.get("spam")).to eq "ham" + end + end describe "coerce arrays fields with default values when null" do config '