Skip to content

Commit 6c79325

Browse files
andselelasticsearch-bot
authored andcommitted
With Elasticsearch 7.10.0 a deprecation log line about types removal is printed for each request (index/bulk) that contains the deprecated index _type.
This commit removes the implicit set of type when connected to Elasticsearch 7.x unless the user doesn't specify explicitly the type. PR #994 Fixes #915
1 parent bcfc364 commit 6c79325

File tree

6 files changed

+25
-7
lines changed

6 files changed

+25
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 10.8.3
2+
- Avoid to implicitly set deprecated type to `_doc` when connects to Elasticsearch version 7.x [#994](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/994)
3+
14
## 10.8.2
25
- [DOC] Update links to use shared attributes [#985](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/985)
36

docs/index.asciidoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ the website landing page or in the {ref}[Elasticsearch documentation].
4040
[NOTE]
4141
================================================================================
4242
When connected to Elasticsearch 7.x, modern versions of this plugin
43-
use the required `_doc` document-type when inserting documents.
43+
don't use the document-type when inserting documents, unless the user
44+
explicitly sets <<plugins-{type}s-{plugin}-document_type>>.
4445
4546
If you are using an earlier version of Logstash and wish to connect to
4647
Elasticsearch 7.x, first upgrade Logstash to version 6.8 to ensure it

lib/logstash/outputs/elasticsearch.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,9 @@ def get_event_type(event)
417417
# @param noop_required_client [nil]: required `nil` for legacy reasons.
418418
# @return [Boolean]
419419
def use_event_type?(noop_required_client)
420-
maximum_seen_major_version < 8
420+
# always set type for ES <= 6
421+
# for ES 7 only set it if the user defined it
422+
(maximum_seen_major_version < 7) || (maximum_seen_major_version == 7 && @document_type)
421423
end
422424

423425
def install_template

logstash-output-elasticsearch.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'logstash-output-elasticsearch'
3-
s.version = '10.8.2'
3+
s.version = '10.8.3'
44

55
s.licenses = ['apache-2.0']
66
s.summary = "Stores logs in Elasticsearch"

spec/integration/outputs/retry_spec.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,21 @@
44
describe "failures in bulk class expected behavior", :integration => true do
55
let(:template) { '{"template" : "not important, will be updated by :index"}' }
66
let(:event1) { LogStash::Event.new("somevalue" => 100, "@timestamp" => "2014-11-17T20:37:17.223Z", "@metadata" => {"retry_count" => 0}) }
7-
let(:action1) { ESHelper.action_for_version(["index", {:_id=>nil, routing_field_name =>nil, :_index=>"logstash-2014.11.17", :_type=> doc_type }, event1]) }
7+
let(:action1) do
8+
if ESHelper.es_version_satisfies?(">= 6", "< 7")
9+
ESHelper.action_for_version(["index", {:_id=>nil, routing_field_name =>nil, :_index=>"logstash-2014.11.17", :_type=> doc_type }, event1])
10+
else
11+
ESHelper.action_for_version(["index", {:_id=>nil, routing_field_name =>nil, :_index=>"logstash-2014.11.17" }, event1])
12+
end
13+
end
814
let(:event2) { LogStash::Event.new("geoip" => { "location" => [ 0.0, 0.0] }, "@timestamp" => "2014-11-17T20:37:17.223Z", "@metadata" => {"retry_count" => 0}) }
9-
let(:action2) { ESHelper.action_for_version(["index", {:_id=>nil, routing_field_name =>nil, :_index=>"logstash-2014.11.17", :_type=> doc_type }, event2]) }
15+
let(:action2) do
16+
if ESHelper.es_version_satisfies?(">= 6", "< 7")
17+
ESHelper.action_for_version(["index", {:_id=>nil, routing_field_name =>nil, :_index=>"logstash-2014.11.17", :_type=> doc_type }, event2])
18+
else
19+
ESHelper.action_for_version(["index", {:_id=>nil, routing_field_name =>nil, :_index=>"logstash-2014.11.17" }, event2])
20+
end
21+
end
1022
let(:invalid_event) { LogStash::Event.new("geoip" => { "location" => "notlatlon" }, "@timestamp" => "2014-11-17T20:37:17.223Z") }
1123

1224
def mock_actions_with_response(*resp)

spec/unit/outputs/elasticsearch_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@
8080
describe "building an event action tuple" do
8181
context "for 7.x elasticsearch clusters" do
8282
let(:maximum_seen_major_version) { 7 }
83-
it "should include '_type'" do
83+
it "should not include '_type' when 'document_type' is not explicitly defined" do
8484
action_tuple = subject.send(:event_action_tuple, LogStash::Event.new("type" => "foo"))
8585
action_params = action_tuple[1]
86-
expect(action_params).to include(:_type => "_doc")
86+
expect(action_params).not_to include(:_type => "_doc")
8787
end
8888

8989
context "with 'document type set'" do

0 commit comments

Comments
 (0)