Skip to content

Commit d860f35

Browse files
committed
Updates content type header for 9.x
1 parent e655e71 commit d860f35

File tree

6 files changed

+34
-6
lines changed

6 files changed

+34
-6
lines changed

elasticsearch-api/lib/elasticsearch/api/actions/bulk.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ def bulk(arguments = {})
163163
body
164164
end
165165

166-
headers.merge!('Content-Type' => 'application/x-ndjson')
166+
headers.merge!({
167+
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9',
168+
'Accept' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
169+
})
167170
Elasticsearch::API::Response.new(
168171
perform_request(method, path, params, payload, headers, request_opts)
169172
)

elasticsearch-api/lib/elasticsearch/api/actions/fleet/msearch.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ def msearch(arguments = {})
9797
payload = body
9898
end
9999

100-
headers.merge!('Content-Type' => 'application/x-ndjson')
100+
headers.merge!({
101+
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9',
102+
'Accept' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
103+
})
101104
Elasticsearch::API::Response.new(
102105
perform_request(method, path, params, payload, headers, request_opts)
103106
)

elasticsearch-api/lib/elasticsearch/api/actions/msearch.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ def msearch(arguments = {})
103103
payload = body
104104
end
105105

106-
headers.merge!('Content-Type' => 'application/x-ndjson')
106+
headers.merge!({
107+
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9',
108+
'Accept' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
109+
})
107110
Elasticsearch::API::Response.new(
108111
perform_request(method, path, params, payload, headers, request_opts)
109112
)

elasticsearch-api/lib/elasticsearch/api/actions/msearch_template.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ def msearch_template(arguments = {})
8181
payload = body
8282
end
8383

84-
headers.merge!('Content-Type' => 'application/x-ndjson')
84+
headers.merge!({
85+
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9',
86+
'Accept' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
87+
})
8588
Elasticsearch::API::Response.new(
8689
perform_request(method, path, params, payload, headers, request_opts)
8790
)

elasticsearch-api/lib/elasticsearch/api/actions/text_structure/find_structure.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ def find_structure(arguments = {})
136136
body
137137
end
138138

139-
headers.merge!('Content-Type' => 'application/x-ndjson')
139+
headers.merge!({
140+
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9',
141+
'Accept' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
142+
})
140143
Elasticsearch::API::Response.new(
141144
perform_request(method, path, params, payload, headers, request_opts)
142145
)

elasticsearch/lib/elasticsearch.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def initialize(arguments = {}, &block)
5252
api_key(arguments) if arguments[:api_key]
5353
setup_cloud(arguments) if arguments[:cloud_id]
5454
set_user_agent!(arguments) unless sent_user_agent?(arguments)
55+
set_content_type!(arguments)
5556
@transport = Elastic::Transport::Client.new(arguments, &block)
5657
end
5758

@@ -175,9 +176,21 @@ def set_user_agent!(arguments)
175176
if RbConfig::CONFIG && RbConfig::CONFIG['host_os']
176177
user_agent << "#{RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase} #{RbConfig::CONFIG['target_cpu']}"
177178
end
179+
set_header({ user_agent: user_agent.join('; ') }, arguments)
180+
end
181+
182+
def set_content_type!(arguments)
183+
headers = {
184+
'content-type' => 'application/vnd.elasticsearch+json; compatible-with=9',
185+
'accept' => 'application/vnd.elasticsearch+json; compatible-with=9,text/plain'
186+
}
187+
set_header(headers, arguments)
188+
end
189+
190+
def set_header(header, arguments)
178191
arguments[:transport_options] ||= {}
179192
arguments[:transport_options][:headers] ||= {}
180-
arguments[:transport_options][:headers].merge!({ user_agent: user_agent.join('; ') })
193+
arguments[:transport_options][:headers].merge!(header)
181194
end
182195
end
183196

0 commit comments

Comments
 (0)