Skip to content

Commit 953a385

Browse files
committed
A bugfix of when setting null values and integrations tests updated which removes non-allowed the fields param.
1 parent 9cf7135 commit 953a385

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

lib/logstash/filters/elasticsearch/esql_executor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def process_response(event, response)
9191
# `unless value.nil?` is a part of `drop_null_columns` that if some of the columns' values are not `nil`, `nil` values appear,
9292
# we should continuously filter them out to achieve full `drop_null_columns` on each individual row (ideal `LIMIT 1` result)
9393
# we also exclude sub-elements of the base field
94-
if row && sub_element_mark_map[column] == false
94+
if row[index] && sub_element_mark_map[column] == false
9595
value_to_set = ESQL_PARSERS_BY_TYPE[column.type].call(row[index])
9696
mapped_data[column.name] = value_to_set
9797
end

spec/filters/integration/elasticsearch_esql_spec.rb

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,12 @@
7272
it "processes the event" do
7373
plugin.filter(event)
7474
expect(event.get("[@metadata][total_values]")).to eq(expected_count)
75-
fields&.each do | old_key, new_key |
76-
expect(event.get(new_key)).not_to be(nil)
75+
fields&.each do | field |
76+
expect(event.get(field)).not_to be(nil)
7777
end
7878
end
7979
end
8080

81-
describe "LIMIT 1 by default" do
82-
let(:config) do
83-
super().merge("query" => "FROM #{es_index}")
84-
end
85-
86-
include_examples "ESQL query execution", 1
87-
end
88-
8981
describe "with simple FROM query with LIMIT" do
9082
let(:config) do
9183
super().merge("query" => "FROM #{es_index} | LIMIT 99")
@@ -102,6 +94,14 @@
10294
include_examples "ESQL query execution", 2
10395
end
10496

97+
describe "with query params" do
98+
let(:config) do
99+
super().merge("query" => "FROM #{es_index} | WHERE type==?type", "query_params" => { "type" => "b" })
100+
end
101+
102+
include_examples "ESQL query execution", 2
103+
end
104+
105105
describe "when invalid query used" do
106106
let(:config) do
107107
super().merge("query" => "FROM undefined index | LIMIT 1")
@@ -114,24 +114,27 @@
114114
end
115115

116116
describe "when field enrichment requested" do
117-
fields = {"message" => "target_message", "count" => "target_count"}
118117
let(:config) do
119-
super().merge("query" => "FROM #{es_index} | WHERE type==\"b\" | LIMIT 99", "fields" => fields)
118+
super().merge("query" => "FROM #{es_index} | WHERE type==\"b\" | LIMIT 99")
120119
end
121120

122-
include_examples "ESQL query execution", 2, fields
121+
include_examples "ESQL query execution", 2, %w[message count]
123122
end
124123

125124
describe "when non-exist field value appear" do
126125
let(:config) do
127-
super().merge("query" => "FROM #{es_index} | LIMIT 99", "fields" => {"message" => "target_message", "count" => "target_count"})
126+
super().merge("query" => "FROM #{es_index}", "target" => "target_field")
128127
end
129128

130129
it "processes the event" do
131130
plugin.filter(event)
132131
expect(event.get("[@metadata][total_values]")).to eq(6)
133-
expect(event.get("target_message").size).to eq(6)
134-
expect(event.get("target_count").size).to eq(5)
132+
expect(event.get("target_field").size).to eq(6)
133+
values = event.get("target_field")
134+
counts = values.count { |entry| entry.key?("count") }
135+
messages = values.count { |entry| entry.key?("message") }
136+
expect(counts).to eq(5)
137+
expect(messages).to eq(6)
135138
end
136139
end
137140
end

0 commit comments

Comments
 (0)