Skip to content

Commit 2ed2d01

Browse files
authored
Revert document type deprecation (#844)
This partially reverts commit 1ba256d.
1 parent 08b912d commit 2ed2d01

File tree

4 files changed

+45
-22
lines changed

4 files changed

+45
-22
lines changed

lib/logstash/outputs/elasticsearch/common.rb

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,15 @@ def event_action_tuple(event)
7777
params[:pipeline] = event.sprintf(@pipeline)
7878
end
7979

80-
if @parent && @join_field
81-
join_value = event.get(@join_field)
82-
parent_value = event.sprintf(@parent)
83-
event.set(@join_field, { "name" => join_value, "parent" => parent_value })
84-
params[routing_field_name] = event.sprintf(@parent)
80+
if @parent
81+
if @join_field
82+
join_value = event.get(@join_field)
83+
parent_value = event.sprintf(@parent)
84+
event.set(@join_field, { "name" => join_value, "parent" => parent_value })
85+
params[routing_field_name] = event.sprintf(@parent)
86+
else
87+
params[:parent] = event.sprintf(@parent)
88+
end
8589
end
8690

8791
if action == 'update'
@@ -255,10 +259,16 @@ def handle_dlq_status(message, action, status, response)
255259
DEFAULT_EVENT_TYPE_ES7="_doc".freeze
256260
def get_event_type(event)
257261
# Set the 'type' value for the index.
258-
type = if client.maximum_seen_major_version < 7
259-
DEFAULT_EVENT_TYPE_ES6
262+
type = if @document_type
263+
event.sprintf(@document_type)
260264
else
261-
DEFAULT_EVENT_TYPE_ES7
265+
if client.maximum_seen_major_version < 6
266+
event.get("type") || DEFAULT_EVENT_TYPE_ES6
267+
elsif client.maximum_seen_major_version == 6
268+
DEFAULT_EVENT_TYPE_ES6
269+
else
270+
DEFAULT_EVENT_TYPE_ES7
271+
end
262272
end
263273

264274
if !(type.is_a?(String) || type.is_a?(Numeric))

lib/logstash/outputs/elasticsearch/common_configs.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def self.included(mod)
1818
mod.config :index, :validate => :string, :default => DEFAULT_INDEX_NAME
1919

2020
mod.config :document_type,
21-
:obsolete => "Multiple document types per index were deprecated in Elasticsearch 6.0 and removed entirely in 7.0. We'll now default to 'doc' on ES 6 and '_doc' in 7"
21+
:validate => :string,
22+
:deprecated => "Document types are being deprecated in Elasticsearch 6.0, and removed entirely in 7.0. You should avoid this feature"
2223

2324
# From Logstash 1.3 onwards, a template is applied to Elasticsearch during
2425
# Logstash's startup if one with the name `template_name` does not already exist.

spec/integration/outputs/parent_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"hosts" => get_host_port,
7676
"index" => index,
7777
"parent" => parent_id,
78+
"document_type" => type,
7879
"join_field" => join_field,
7980
"manage_template" => false
8081
}
@@ -89,6 +90,7 @@
8990
"hosts" => get_host_port,
9091
"index" => index,
9192
"parent" => "%{link_to}",
93+
"document_type" => type,
9294
"join_field" => join_field,
9395
"manage_template" => false
9496
}

spec/unit/outputs/elasticsearch_spec.rb

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,34 @@
4444
let(:manticore_url) { manticore_urls.first }
4545

4646
describe "getting a document type" do
47-
context "for 7.x elasticsearch clusters" do
48-
let(:maximum_seen_major_version) { 7 }
49-
it "should return '_doc'" do
50-
expect(subject.send(:get_event_type, LogStash::Event.new("type" => "foo"))).to eql("_doc")
47+
context "if document_type isn't set" do
48+
let(:options) { super.merge("document_type" => nil)}
49+
context "for 7.x elasticsearch clusters" do
50+
let(:maximum_seen_major_version) { 7 }
51+
it "should return '_doc'" do
52+
expect(subject.send(:get_event_type, LogStash::Event.new("type" => "foo"))).to eql("_doc")
53+
end
54+
end
55+
56+
context "for 6.x elasticsearch clusters" do
57+
let(:maximum_seen_major_version) { 6 }
58+
it "should return 'doc'" do
59+
expect(subject.send(:get_event_type, LogStash::Event.new("type" => "foo"))).to eql("doc")
60+
end
5161
end
52-
end
5362

54-
context "for 6.x elasticsearch clusters" do
55-
let(:maximum_seen_major_version) { 6 }
56-
it "should return 'doc'" do
57-
expect(subject.send(:get_event_type, LogStash::Event.new("type" => "foo"))).to eql("doc")
63+
context "for < 6.0 elasticsearch clusters" do
64+
let(:maximum_seen_major_version) { 5 }
65+
it "should get the type from the event" do
66+
expect(subject.send(:get_event_type, LogStash::Event.new("type" => "foo"))).to eql("foo")
67+
end
5868
end
5969
end
6070

61-
context "for < 6.0 elasticsearch clusters" do
62-
let(:maximum_seen_major_version) { 5 }
63-
it "should return 'doc'" do
64-
expect(subject.send(:get_event_type, LogStash::Event.new("type" => "foo"))).to eql("doc")
71+
context "with 'document type set'" do
72+
let(:options) { super.merge("document_type" => "bar")}
73+
it "should get the event type from the 'document_type' setting" do
74+
expect(subject.send(:get_event_type, LogStash::Event.new())).to eql("bar")
6575
end
6676
end
6777
end

0 commit comments

Comments
 (0)