@@ -73,6 +73,7 @@ def initialize(retry_stream)
7373 DEFAULT_RELOAD_AFTER = -1
7474 DEFAULT_TARGET_BULK_BYTES = -1
7575 DEFAULT_POLICY_ID = "logstash-policy"
76+ ES9_CONTENT_TYPE = "application/vnd.elasticsearch+x-ndjson; compatible-with=9"
7677
7778 config_param :host , :string , :default => 'localhost'
7879 config_param :port , :integer , :default => 9200
@@ -146,7 +147,7 @@ def initialize(retry_stream)
146147 config_param :sniffer_class_name , :string , :default => nil
147148 config_param :selector_class_name , :string , :default => nil
148149 config_param :reload_after , :integer , :default => DEFAULT_RELOAD_AFTER
149- config_param :content_type , :enum , list : [ :"application/json" , :"application/x-ndjson" ] , :default => :"application/json" ,
150+ config_param :content_type , :enum , list : [ :"application/json" , :"application/x-ndjson" , :" #{ ES9_CONTENT_TYPE } " ] , :default => :"application/json" ,
150151 :deprecated => <<EOC
151152elasticsearch gem v6.0.2 starts to use correct Content-Type. Please upgrade elasticserach gem and stop to use this option.
152153see: https://github.com/elastic/elasticsearch-ruby/pull/514
@@ -350,10 +351,20 @@ class << self
350351 log . warn "Detected ES 7.x: `_doc` will be used as the document `_type`."
351352 @type_name = '_doc' . freeze
352353 end
353- if @last_seen_major_version > = 8 && @type_name != DEFAULT_TYPE_NAME_ES_7x
354- log . debug "Detected ES 8.x or above : This parameter has no effect."
354+ if @last_seen_major_version = = 8 && @type_name != DEFAULT_TYPE_NAME_ES_7x
355+ log . debug "Detected ES 8.x: This parameter has no effect."
355356 @type_name = nil
356357 end
358+ if @last_seen_major_version >= 9
359+ if @type_name != DEFAULT_TYPE_NAME_ES_7x
360+ log . debug "Detected ES 9.x or above: This parameter has no effect."
361+ @type_name = nil
362+ end
363+ if @content_type != ES9_CONTENT_TYPE
364+ log . trace "Detected ES 9.x or above: Content-Type will be adjusted."
365+ @content_type = ES9_CONTENT_TYPE
366+ end
367+ end
357368 end
358369
359370 if @validate_client_version && !dry_run?
0 commit comments