Skip to content

Commit cb6af35

Browse files
committed
Updates content type header for 9.x
1 parent 7fc4dbc commit cb6af35

File tree

12 files changed

+66
-22
lines changed

12 files changed

+66
-22
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ 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+
})
167169
Elasticsearch::API::Response.new(
168170
perform_request(method, path, params, payload, headers, request_opts)
169171
)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ 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+
})
101103
Elasticsearch::API::Response.new(
102104
perform_request(method, path, params, payload, headers, request_opts)
103105
)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ 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+
})
107109
Elasticsearch::API::Response.new(
108110
perform_request(method, path, params, payload, headers, request_opts)
109111
)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ 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+
})
8587
Elasticsearch::API::Response.new(
8688
perform_request(method, path, params, payload, headers, request_opts)
8789
)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ 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+
})
140142
Elasticsearch::API::Response.new(
141143
perform_request(method, path, params, payload, headers, request_opts)
142144
)

elasticsearch-api/lib/elasticsearch/api/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
module Elasticsearch
1919
module API
2020
VERSION = '9.0.0'.freeze
21-
ES_SPECIFICATION_COMMIT = 'cbfcc73d01310bed2a480ec35aaef98138b598e5'.freeze
21+
ES_SPECIFICATION_COMMIT = 'cd9c33775947086a99e6cf299b87733ba0111c28'.freeze
2222
end
2323
end

elasticsearch-api/spec/unit/actions/bulk_spec.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,17 @@
2525
params,
2626
body,
2727
headers,
28-
{:endpoint=>"bulk"}
28+
{ endpoint: 'bulk' }
2929
]
3030
end
3131

32-
let(:headers) { { 'Content-Type' => 'application/x-ndjson' } }
32+
let(:headers) {
33+
{
34+
'Accept' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9',
35+
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
36+
}
37+
}
38+
3339
let(:params) { {} }
3440
let(:url) { '_bulk' }
3541
let(:body) { '' }

elasticsearch-api/spec/unit/actions/fleet/msearch_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,18 @@
2424
'_fleet/_fleet_msearch',
2525
{},
2626
{},
27-
{ 'Content-Type' => 'application/x-ndjson' },
27+
headers,
2828
{ endpoint: 'fleet.msearch' }
2929
]
3030
end
3131

32+
let(:headers) {
33+
{
34+
'Accept' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9',
35+
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
36+
}
37+
}
38+
3239
it 'performs the request' do
3340
expect(client_double.fleet.msearch(body: {})).to be_a Elasticsearch::API::Response
3441
end

elasticsearch-api/spec/unit/actions/msearch_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@
4141
{}
4242
end
4343

44-
let(:headers) do
45-
{ 'Content-Type' => 'application/x-ndjson' }
46-
end
44+
let(:headers) {
45+
{
46+
'Accept' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9',
47+
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
48+
}
49+
}
4750

4851
let(:client) do
4952
Class.new { include Elasticsearch::API }.new
@@ -89,7 +92,6 @@
8992
end
9093

9194
context 'when an index is specified' do
92-
9395
let(:url) do
9496
'foo/_msearch'
9597
end
@@ -115,7 +117,6 @@
115117
end
116118

117119
context 'when multiple indices are specified' do
118-
119120
let(:url) do
120121
'foo,bar/_msearch'
121122
end

elasticsearch-api/spec/unit/actions/msearch_template_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,18 @@
3737
{}
3838
end
3939

40-
let(:headers) do
41-
{ 'Content-Type' => 'application/x-ndjson' }
42-
end
40+
let(:headers) {
41+
{
42+
'Accept' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9',
43+
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
44+
}
45+
}
4346

4447
let(:url) do
4548
'_msearch/template'
4649
end
4750

4851
context 'when a body is provided as a document' do
49-
5052
let(:body) do
5153
<<-PAYLOAD.gsub(/^\s+/, '')
5254
{"index":"foo"}
@@ -67,7 +69,6 @@
6769
end
6870

6971
context 'when a body is provided as a string' do
70-
7172
let(:body) do
7273
%Q|{"foo":"bar"}\n{"moo":"lam"}|
7374
end
@@ -78,7 +79,6 @@
7879
end
7980

8081
context 'when an index is provided' do
81-
8282
let(:url) do
8383
'foo/_msearch/template'
8484
end

elasticsearch-api/spec/unit/actions/text_structure/find_structure_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,18 @@
2424
'_text_structure/find_structure',
2525
{},
2626
{},
27-
{ 'Content-Type' => 'application/x-ndjson' },
27+
headers,
2828
{ endpoint: 'text_structure.find_structure' }
2929
]
3030
end
3131

32+
let(:headers) {
33+
{
34+
'Accept' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9',
35+
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
36+
}
37+
}
38+
3239
it 'performs the request' do
3340
expect(client_double.text_structure.find_structure(body: {})).to be_a Elasticsearch::API::Response
3441
end

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'
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)