Skip to content

Updates API generated code, headers #2659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion elasticsearch-api/lib/elasticsearch/api/actions/bulk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ def bulk(arguments = {})
body
end

headers.merge!('Content-Type' => 'application/x-ndjson')
headers.merge!({
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
})
Elasticsearch::API::Response.new(
perform_request(method, path, params, payload, headers, request_opts)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ def msearch(arguments = {})
payload = body
end

headers.merge!('Content-Type' => 'application/x-ndjson')
headers.merge!({
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
})
Elasticsearch::API::Response.new(
perform_request(method, path, params, payload, headers, request_opts)
)
Expand Down
4 changes: 3 additions & 1 deletion elasticsearch-api/lib/elasticsearch/api/actions/msearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ def msearch(arguments = {})
payload = body
end

headers.merge!('Content-Type' => 'application/x-ndjson')
headers.merge!({
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
})
Elasticsearch::API::Response.new(
perform_request(method, path, params, payload, headers, request_opts)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def msearch_template(arguments = {})
payload = body
end

headers.merge!('Content-Type' => 'application/x-ndjson')
headers.merge!({
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
})
Elasticsearch::API::Response.new(
perform_request(method, path, params, payload, headers, request_opts)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ def find_structure(arguments = {})
body
end

headers.merge!('Content-Type' => 'application/x-ndjson')
headers.merge!({
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
})
Elasticsearch::API::Response.new(
perform_request(method, path, params, payload, headers, request_opts)
)
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch-api/lib/elasticsearch/api/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
module Elasticsearch
module API
VERSION = '9.0.0'.freeze
ES_SPECIFICATION_COMMIT = 'cbfcc73d01310bed2a480ec35aaef98138b598e5'.freeze
ES_SPECIFICATION_COMMIT = 'cd9c33775947086a99e6cf299b87733ba0111c28'.freeze
end
end
9 changes: 7 additions & 2 deletions elasticsearch-api/spec/unit/actions/bulk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@
params,
body,
headers,
{:endpoint=>"bulk"}
{ endpoint: 'bulk' }
]
end

let(:headers) { { 'Content-Type' => 'application/x-ndjson' } }
let(:headers) {
{
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
}
}

let(:params) { {} }
let(:url) { '_bulk' }
let(:body) { '' }
Expand Down
8 changes: 7 additions & 1 deletion elasticsearch-api/spec/unit/actions/fleet/msearch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@
'_fleet/_fleet_msearch',
{},
{},
{ 'Content-Type' => 'application/x-ndjson' },
headers,
{ endpoint: 'fleet.msearch' }
]
end

let(:headers) {
{
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
}
}

it 'performs the request' do
expect(client_double.fleet.msearch(body: {})).to be_a Elasticsearch::API::Response
end
Expand Down
10 changes: 5 additions & 5 deletions elasticsearch-api/spec/unit/actions/msearch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@
{}
end

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

let(:client) do
Class.new { include Elasticsearch::API }.new
Expand Down Expand Up @@ -89,7 +91,6 @@
end

context 'when an index is specified' do

let(:url) do
'foo/_msearch'
end
Expand All @@ -115,7 +116,6 @@
end

context 'when multiple indices are specified' do

let(:url) do
'foo,bar/_msearch'
end
Expand Down
11 changes: 5 additions & 6 deletions elasticsearch-api/spec/unit/actions/msearch_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@
{}
end

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

let(:url) do
'_msearch/template'
end

context 'when a body is provided as a document' do

let(:body) do
<<-PAYLOAD.gsub(/^\s+/, '')
{"index":"foo"}
Expand All @@ -67,7 +68,6 @@
end

context 'when a body is provided as a string' do

let(:body) do
%Q|{"foo":"bar"}\n{"moo":"lam"}|
end
Expand All @@ -78,7 +78,6 @@
end

context 'when an index is provided' do

let(:url) do
'foo/_msearch/template'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@
'_text_structure/find_structure',
{},
{},
{ 'Content-Type' => 'application/x-ndjson' },
headers,
{ endpoint: 'text_structure.find_structure' }
]
end

let(:headers) {
{
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
}
}

it 'performs the request' do
expect(client_double.text_structure.find_structure(body: {})).to be_a Elasticsearch::API::Response
end
Expand Down
15 changes: 14 additions & 1 deletion elasticsearch/lib/elasticsearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def initialize(arguments = {}, &block)
api_key(arguments) if arguments[:api_key]
setup_cloud(arguments) if arguments[:cloud_id]
set_user_agent!(arguments) unless sent_user_agent?(arguments)
set_content_type!(arguments)
@transport = Elastic::Transport::Client.new(arguments, &block)
end

Expand Down Expand Up @@ -175,9 +176,21 @@ def set_user_agent!(arguments)
if RbConfig::CONFIG && RbConfig::CONFIG['host_os']
user_agent << "#{RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase} #{RbConfig::CONFIG['target_cpu']}"
end
set_header({ user_agent: user_agent.join('; ') }, arguments)
end

def set_content_type!(arguments)
headers = {
'content-type' => 'application/vnd.elasticsearch+json; compatible-with=9',
'accept' => 'application/vnd.elasticsearch+json; compatible-with=9'
}
set_header(headers, arguments)
end

def set_header(header, arguments)
arguments[:transport_options] ||= {}
arguments[:transport_options][:headers] ||= {}
arguments[:transport_options][:headers].merge!({ user_agent: user_agent.join('; ') })
arguments[:transport_options][:headers].merge!(header)
end
end

Expand Down