Skip to content

Commit cc45a0a

Browse files
andselyaauie
andauthored
Avoid to store nil values for version_type, version and routing
Adding `version => nil` is a change in behaviour because, actually it's never added, so this commit respect the existing logic, do not add event's keys that are empty Co-authored-by: Ry Biesemeyer <[email protected]>
1 parent 6508c0e commit cc45a0a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/logstash/outputs/elasticsearch.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,8 @@ def common_event_params(event)
557557
params[:version] = resolve_version(event, event_version)
558558
params[:version_type] = resolve_version_type(event, event_version_type)
559559

560-
params
560+
# purge nil valued key-value pairs
561+
params.compact
561562
end
562563

563564
def resolve_version(event, event_version)

spec/unit/outputs/elasticsearch_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@
304304

305305
context "when the event DOESN'T contain an integration metadata version" do
306306
it "plugin's default id mechanism is used" do
307-
expect(subject.send(:event_action_tuple, event)[1]).to include(:version => nil)
307+
expect(subject.send(:event_action_tuple, event)[1]).to_not include(:version)
308308
end
309309
end
310310
end
@@ -338,7 +338,7 @@
338338

339339
context "when the event DOESN'T contain an integration metadata version_type" do
340340
it "plugin's default id mechanism is used" do
341-
expect(subject.send(:event_action_tuple, event)[1]).to include(:version_type => nil)
341+
expect(subject.send(:event_action_tuple, event)[1]).to_not include(:version_type)
342342
end
343343
end
344344
end
@@ -372,7 +372,7 @@
372372

373373
context "when the event DOESN'T contain an integration metadata routing" do
374374
it "plugin's default id mechanism is used" do
375-
expect(subject.send(:event_action_tuple, event)[1]).to include(:routing => nil)
375+
expect(subject.send(:event_action_tuple, event)[1]).to_not include(:routing)
376376
end
377377
end
378378
end

0 commit comments

Comments
 (0)