Skip to content

Commit e4155ad

Browse files
committed
Fix #239 - interpolated action "update" don't get params "upsert" and "script"
1 parent 4abd353 commit e4155ad

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/logstash/outputs/elasticsearch/common.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def multi_receive(events)
3232

3333
# Convert the event into a 3-tuple of action, params, and event
3434
def event_action_tuple(event)
35-
params = event_action_params(event)
3635
action = event.sprintf(@action)
36+
params = event_action_params(action, event)
3737
[action, params, event]
3838
end
3939

@@ -123,8 +123,8 @@ def submit(actions)
123123
actions_to_retry
124124
end
125125

126-
# get the action parameters for the given event
127-
def event_action_params(event)
126+
# get the action parameters for the given action and event
127+
def event_action_params(action, event)
128128
type = get_event_type(event)
129129

130130
params = {
@@ -135,7 +135,7 @@ def event_action_params(event)
135135
}
136136

137137
params[:parent] = event.sprintf(@parent) if @parent
138-
if @action == 'update'
138+
if action == 'update'
139139
params[:_upsert] = LogStash::Json.load(event.sprintf(@upsert)) if @upsert != ""
140140
params[:_script] = event.sprintf(@script) if @script != ""
141141
end

spec/unit/outputs/elasticsearch_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,13 @@
157157
describe "the action option" do
158158
subject(:eso) {LogStash::Outputs::ElasticSearch.new(options)}
159159
context "with a sprintf action" do
160-
let(:options) { {"action" => "%{myactionfield}"} }
160+
let(:options) { {"action" => "%{myactionfield}", "upsert" => '{"message": "some text"}'} }
161161

162162
let(:event) { LogStash::Event.new("myactionfield" => "update", "message" => "blah") }
163163

164-
it "should interpolate the requested action value when creating an event_action_tuple" do
164+
it "should interpolate the requested action value when creating an event_action_tuple and obtain associated action params" do
165165
expect(eso.event_action_tuple(event).first).to eql("update")
166+
expect(eso.event_action_tuple(event)[1]).to include(:_upsert)
166167
end
167168
end
168169

0 commit comments

Comments
 (0)