Skip to content

Commit 8e19a6b

Browse files
committed
Updates content type header for 9.x
1 parent 4d92939 commit 8e19a6b

File tree

11 files changed

+60
-21
lines changed

11 files changed

+60
-21
lines changed

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

+3-1
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

+3-1
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

+3-1
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

+3-1
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

+3-1
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/spec/unit/actions/bulk_spec.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,16 @@
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+
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
35+
}
36+
}
37+
3338
let(:params) { {} }
3439
let(:url) { '_bulk' }
3540
let(:body) { '' }

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@
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+
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
35+
}
36+
}
37+
3238
it 'performs the request' do
3339
expect(client_double.fleet.msearch(body: {})).to be_a Elasticsearch::API::Response
3440
end

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@
4141
{}
4242
end
4343

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

4850
let(:client) do
4951
Class.new { include Elasticsearch::API }.new
@@ -89,7 +91,6 @@
8991
end
9092

9193
context 'when an index is specified' do
92-
9394
let(:url) do
9495
'foo/_msearch'
9596
end
@@ -115,7 +116,6 @@
115116
end
116117

117118
context 'when multiple indices are specified' do
118-
119119
let(:url) do
120120
'foo,bar/_msearch'
121121
end

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

+5-6
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,17 @@
3737
{}
3838
end
3939

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

4446
let(:url) do
4547
'_msearch/template'
4648
end
4749

4850
context 'when a body is provided as a document' do
49-
5051
let(:body) do
5152
<<-PAYLOAD.gsub(/^\s+/, '')
5253
{"index":"foo"}
@@ -67,7 +68,6 @@
6768
end
6869

6970
context 'when a body is provided as a string' do
70-
7171
let(:body) do
7272
%Q|{"foo":"bar"}\n{"moo":"lam"}|
7373
end
@@ -78,7 +78,6 @@
7878
end
7979

8080
context 'when an index is provided' do
81-
8281
let(:url) do
8382
'foo/_msearch/template'
8483
end

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@
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+
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
35+
}
36+
}
37+
3238
it 'performs the request' do
3339
expect(client_double.text_structure.find_structure(body: {})).to be_a Elasticsearch::API::Response
3440
end

elasticsearch/lib/elasticsearch.rb

+14-1
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)