Skip to content
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: 2 additions & 2 deletions .github/workflows/otel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: opentelemetry
on:
push:
branches:
- main
- 9.3
pull_request:
branches:
- main
- 9.3
jobs:
test-otel:
name: 'Test Open Telemetry'
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
**See the full release notes on the official documentation website: https://www.elastic.co/docs/release-notes/elasticsearch/clients/ruby**

# 9.3.4

* Fixes header conflict when using Elasticsearch Serverless. [Pull Request](https://github.com/elastic/elasticsearch-ruby/pull/2984)

# 9.3.3

* Fixes NoMethodError when `Content-Type` lacks `compatible-with` parameter. [Pull Request](https://github.com/elastic/elasticsearch-ruby/pull/2974)
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 @@ -17,7 +17,7 @@

module Elasticsearch
module API
VERSION = '9.3.3'.freeze
VERSION = '9.3.4'.freeze
ES_SPECIFICATION_COMMIT = '31789f4216047ef7ba7969e31610fa2bbfe696b1'.freeze
end
end
8 changes: 7 additions & 1 deletion elasticsearch-api/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@
end
require 'elasticsearch'
require 'elasticsearch-api'
require 'jbuilder'
require 'jsonify'
require 'logger'
require 'openssl'
require 'yaml'

# TODO: There is a dependency issue with JRuby 9.4.15.0 and JBuilder at the moment:
def jruby_exception?
defined?(JRUBY_VERSION) &&
JRUBY_VERSION.between?('9.4', '9.5')
end
require 'jbuilder' unless jruby_exception?

tracer = ::Logger.new(STDERR)
tracer.formatter = lambda { |s, d, p, m| "#{m.gsub(/^.*$/) { |n| ' ' + n } }\n" }

Expand Down
3 changes: 2 additions & 1 deletion elasticsearch-api/spec/unit/actions/json_builders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,5 @@
expect(client_double.search(body: json)).to be_a Elasticsearch::API::Response
end
end
end
end unless jruby_exception?
# TODO: Exception for JRuby v9.4.15.0 ^
2 changes: 1 addition & 1 deletion elasticsearch/elasticsearch.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Gem::Specification.new do |s|
s.rdoc_options = ['--charset=UTF-8']

s.required_ruby_version = '>= 2.6' # For compatibility with JRuby 9.3
s.add_dependency 'elasticsearch-api', '9.3.3'
s.add_dependency 'elasticsearch-api', '9.3.4'
s.add_dependency 'elastic-transport', '~> 8.3'

s.add_development_dependency 'base64'
Expand Down
8 changes: 6 additions & 2 deletions elasticsearch/lib/elasticsearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,19 @@ def set_user_agent!(arguments)
def set_content_type!(arguments)
headers = {}
user_headers = arguments&.[](:transport_options)&.[](:headers)
unless user_headers&.keys&.detect { |h| h =~ /content-?_?type/i }
unless user_headers&.keys&.detect { |h| h =~ /content-?_?type/i } || api_version_set?(user_headers)
headers['content-type'] = 'application/vnd.elasticsearch+json; compatible-with=9'
end
unless user_headers&.keys&.detect { |h| h =~ /accept/i }
unless user_headers&.keys&.detect { |h| h =~ /accept/i } || api_version_set?(user_headers)
headers['accept'] = 'application/vnd.elasticsearch+json; compatible-with=9'
end
set_header(headers, arguments) unless headers.empty?
end

def api_version_set?(headers)
!!headers&.keys&.find { |a| a.match?(/elastic-api-version/i) }
end

def set_header(header, arguments)
arguments[:transport_options] ||= {}
arguments[:transport_options][:headers] ||= {}
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch/lib/elasticsearch/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
# under the License.

module Elasticsearch
VERSION = '9.3.3'.freeze
VERSION = '9.3.4'.freeze
end
22 changes: 22 additions & 0 deletions elasticsearch/spec/unit/headers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,26 @@
client.search
end
end

context 'when Elastic-Api-Version header is set' do
let!(:client) do
described_class.new(
host: 'http://localhost:9200',
transport_options: { headers: { 'Elastic-Api-Version' => '2023-10-31' } }
).tap do |client|
client.instance_variable_set('@verified', true)
end
end

it 'does not modify the content-type header' do
expected_headers = client.transport.connections.connections.first.connection.headers
expect(expected_headers['Content-Type']).to eq 'application/json'
expect(expected_headers['Elastic-Api-Version']).to eq '2023-10-31'

expect_any_instance_of(Faraday::Connection)
.to receive(:run_request)
.with(:get, 'http://localhost:9200/_search', nil, expected_headers) { OpenStruct.new(body: '') }
client.search
end
end
end
Loading