elasticsearch 8.12.2 → 8.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5241bcaae583bd2a3f2a333c2694de1b05af8428d572a74b127baa08f000a172
4
- data.tar.gz: 57ba5a1bd7d8f43d65671dd7adc9e90c4db1b056164f38a5a4bf7b979bb29631
3
+ metadata.gz: 81edddb9e4103d40bc3b06bb4fd1db49e8a62f17fab3fa914d737069d681d526
4
+ data.tar.gz: 29f8aa207a8e7e5a446a0fa0c6bc1bdb408f49020c53fbdaeba0066d4807306f
5
5
  SHA512:
6
- metadata.gz: 7190459564453bab3661d6e8528d8cd0ab612654846467fd9d2c81cc05dab49f36d04d57dc7ac2120cf3e5d49b1ed1b005f33c9a383f62c4451f60d5b93aa660
7
- data.tar.gz: '01921137542be51cd96dd1bd5edf0b5f65e1bdf457673236e62167a559bf9b64312bae6c15a69cfc97b468a5f02a1e8f05bf57801d19aeeb2b984dc1ab83d4ba'
6
+ metadata.gz: 00e2fd8d54aa598c24e5b3e8f1452b117f65c951e30988b1927e8e504eda77027557d5963bdbec22d3e747c53f32eec3aae8a44e7a6b4f37edb336d894c01ce1
7
+ data.tar.gz: aa738720a203ddf228ce4835e2aaa3ad5b1bf2ed7380d7ba6f451630b831219cd7dfd17b016489350d12a7e62f2bad456a3a82368fbb53fa27720f92f79f4945
data/Gemfile CHANGED
@@ -29,3 +29,7 @@ end
29
29
  if ENV['TRANSPORT_VERSION'] == 'main'
30
30
  gem 'elastic-transport', git: 'https://github.com/elastic/elastic-transport-ruby.git', branch: 'main'
31
31
  end
32
+
33
+ if RUBY_VERSION >= '3.0'
34
+ gem 'opentelemetry-sdk', require: false
35
+ end
@@ -46,11 +46,11 @@ Gem::Specification.new do |s|
46
46
  s.required_ruby_version = '>= 2.5'
47
47
 
48
48
  s.add_dependency 'elastic-transport', '~> 8.3'
49
- s.add_dependency 'elasticsearch-api', '8.12.2'
50
-
49
+ s.add_dependency 'elasticsearch-api', '8.13.0'
50
+
51
51
  s.add_development_dependency 'base64'
52
52
  s.add_development_dependency 'bundler'
53
- s.add_development_dependency 'byebug' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
53
+ s.add_development_dependency 'debug' unless defined?(JRUBY_VERSION)
54
54
  s.add_development_dependency 'pry'
55
55
  s.add_development_dependency 'rake'
56
56
  s.add_development_dependency 'require-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
@@ -0,0 +1,71 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ module Elasticsearch
19
+ module Helpers
20
+ # Elasticsearch Client Helper for the ES|QL API
21
+ #
22
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/esql-query-api.html
23
+ #
24
+ module ESQLHelper
25
+ # Query helper for ES|QL
26
+ #
27
+ # By default, the `esql.query` API returns a Hash response with the following keys:
28
+ #
29
+ # * `columns` with the value being an Array of `{ name: type }` Hashes for each column.
30
+ #
31
+ # * `values` with the value being an Array of Arrays with the values for each row.
32
+ #
33
+ # This helper function returns an Array of hashes with the columns as keys and the respective
34
+ # values: `{ column['name'] => value }`.
35
+ #
36
+ # @param client [Elasticsearch::Client] an instance of the Client to use for the query.
37
+ # @param query [Hash, String] The query to be passed to the ES|QL query API.
38
+ # @param params [Hash] options to pass to the ES|QL query API.
39
+ # @param parser [Hash] Hash of column name keys and Proc values to transform the value of
40
+ # a given column.
41
+ # @example Using the ES|QL helper
42
+ # require 'elasticsearch/helpers/esql_helper'
43
+ # query = <<~ESQL
44
+ # FROM sample_data
45
+ # | EVAL duration_ms = ROUND(event.duration / 1000000.0, 1)
46
+ # ESQL
47
+ # response = Elasticsearch::Helpers::ESQLHelper.query(client, query)
48
+ #
49
+ # @example Using the ES|QL helper with a parser
50
+ # response = Elasticsearch::Helpers::ESQLHelper.query(
51
+ # client,
52
+ # query,
53
+ # parser: { '@timestamp' => Proc.new { |t| DateTime.parse(t) } }
54
+ # )
55
+ #
56
+ # @see https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/Helpers.html#_esql_helper
57
+ #
58
+ def self.query(client, query, params = {}, parser: {})
59
+ response = client.esql.query({ body: { query: query }, format: 'json' }.merge(params))
60
+ columns = response['columns']
61
+ response['values'].map do |value|
62
+ (value.length - 1).downto(0).map do |index|
63
+ key = columns[index]['name']
64
+ value[index] = parser[key].call value[index] if parser[key]
65
+ { key => value[index] }
66
+ end.reduce({}, :merge)
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -16,5 +16,5 @@
16
16
  # under the License.
17
17
 
18
18
  module Elasticsearch
19
- VERSION = '8.12.2'.freeze
19
+ VERSION = '8.13.0'.freeze
20
20
  end
data/lib/elasticsearch.rb CHANGED
@@ -60,10 +60,6 @@ module Elasticsearch
60
60
  elsif name == :perform_request
61
61
  # The signature for perform_request is:
62
62
  # method, path, params, body, headers, opts
63
- # The last arg is opts, which shouldn't be sent when `perform_request` is called
64
- # directly. Check if :endpoint is a key, which means it's the extra identifier
65
- # used for OpenTelemetry.
66
- args.pop if args[-1].is_a?(Hash) && args[-1][:endpoint]
67
63
  if (opaque_id = args[2]&.delete(:opaque_id))
68
64
  headers = args[4] || {}
69
65
  opaque_id = @opaque_id_prefix ? "#{@opaque_id_prefix}#{opaque_id}" : opaque_id
@@ -54,7 +54,7 @@ context 'Elasticsearch client' do
54
54
  end
55
55
 
56
56
  context 'Reports the right meta header' do
57
- it 'Reports es service name and gem versio' do
57
+ it 'Reports es service name and gem version' do
58
58
  headers = client.transport.connections.first.connection.headers
59
59
  version = Class.new.extend(Elastic::Transport::MetaHeader).send(:client_meta_version, Elasticsearch::VERSION)
60
60
  expect(headers['x-elastic-client-meta']).to match /^es=#{version}/
@@ -14,22 +14,12 @@
14
14
  # KIND, either express or implied. See the License for the
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
- ELASTICSEARCH_URL = ENV['TEST_ES_SERVER'] || "http://localhost:#{(ENV['PORT'] || 9200)}"
18
- raise URI::InvalidURIError unless ELASTICSEARCH_URL =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/
19
-
17
+ require_relative 'helpers_spec_helper'
20
18
  require 'elasticsearch/helpers/bulk_helper'
21
- require 'spec_helper'
22
19
  require 'tempfile'
23
20
 
24
21
  context 'Elasticsearch client helpers' do
25
22
  context 'Bulk helper' do
26
- let(:client) do
27
- Elasticsearch::Client.new(
28
- host: ELASTICSEARCH_URL,
29
- user: 'elastic',
30
- password: 'changeme'
31
- )
32
- end
33
23
  let(:index) { 'bulk_animals' }
34
24
  let(:params) { { refresh: 'wait_for' } }
35
25
  let(:bulk_helper) { Elasticsearch::Helpers::BulkHelper.new(client, index, params) }
@@ -0,0 +1,94 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+ require_relative 'helpers_spec_helper'
18
+ require 'elasticsearch/helpers/esql_helper'
19
+
20
+ context 'Elasticsearch client helpers' do
21
+ let(:index) { 'esql_helper_test' }
22
+ let(:body) { { size: 12, query: { match_all: {} } } }
23
+ let(:esql_helper) { Elasticsearch::Helpers::ESQLHelper }
24
+ let(:query) do
25
+ <<~ESQL
26
+ FROM #{index}
27
+ | EVAL duration_ms = ROUND(event.duration / 1000000.0, 1)
28
+ ESQL
29
+ end
30
+
31
+ before do
32
+ client.indices.create(
33
+ index: index,
34
+ body: {
35
+ mappings: {
36
+ properties: { 'client.ip' => { type: 'ip' }, message: { type: 'keyword' } }
37
+ }
38
+ }
39
+ )
40
+ client.bulk(
41
+ index: index,
42
+ body: [
43
+ {'index': {}},
44
+ {'@timestamp' => '2023-10-23T12:15:03.360Z', 'client.ip' => '172.21.2.162', message: 'Connected to 10.1.0.3', 'event.duration' => 3450233},
45
+ {'index': {}},
46
+ {'@timestamp' => '2023-10-23T12:27:28.948Z', 'client.ip' => '172.21.2.113', message: 'Connected to 10.1.0.2', 'event.duration' => 2764889},
47
+ {'index': {}},
48
+ {'@timestamp' => '2023-10-23T13:33:34.937Z', 'client.ip' => '172.21.0.5', message: 'Disconnected', 'event.duration' => 1232382},
49
+ {'index': {}},
50
+ {'@timestamp' => '2023-10-23T13:51:54.732Z', 'client.ip' => '172.21.3.15', message: 'Connection error', 'event.duration' => 725448},
51
+ {'index': {}},
52
+ {'@timestamp' => '2023-10-23T13:52:55.015Z', 'client.ip' => '172.21.3.15', message: 'Connection error', 'event.duration' => 8268153},
53
+ {'index': {}},
54
+ {'@timestamp' => '2023-10-23T13:53:55.832Z', 'client.ip' => '172.21.3.15', message: 'Connection error', 'event.duration' => 5033755},
55
+ {'index': {}},
56
+ {'@timestamp' => '2023-10-23T13:55:01.543Z', 'client.ip' => '172.21.3.15', message: 'Connected to 10.1.0.1', 'event.duration' => 1756467}
57
+ ],
58
+ refresh: true
59
+ )
60
+ end
61
+
62
+ after do
63
+ client.indices.delete(index: index)
64
+ end
65
+
66
+ it 'returns an ESQL response as a relational key/value object' do
67
+ response = esql_helper.query(client, query)
68
+ expect(response.count).to eq 7
69
+ expect(response.first.keys).to eq ['duration_ms', 'message', 'event.duration', 'client.ip', '@timestamp']
70
+ response.each do |r|
71
+ expect(r['@timestamp']).to be_a String
72
+ expect(r['client.ip']).to be_a String
73
+ expect(r['message']).to be_a String
74
+ expect(r['event.duration']).to be_a Integer
75
+ end
76
+ end
77
+
78
+ it 'parses iterated objects when procs are passed in' do
79
+ require 'ipaddr'
80
+
81
+ parser = {
82
+ '@timestamp' => Proc.new { |t| DateTime.parse(t) },
83
+ 'client.ip' => Proc.new { |i| IPAddr.new(i) },
84
+ 'event.duration' => Proc.new { |d| d.to_s }
85
+ }
86
+ response = esql_helper.query(client, query, parser: parser)
87
+ response.each do |r|
88
+ expect(r['@timestamp']).to be_a DateTime
89
+ expect(r['client.ip']).to be_a IPAddr
90
+ expect(r['message']).to be_a String
91
+ expect(r['event.duration']).to be_a String
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,29 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ require 'spec_helper'
19
+
20
+ ELASTICSEARCH_URL = ENV['TEST_ES_SERVER'] || "http://localhost:#{(ENV['PORT'] || 9200)}"
21
+ raise URI::InvalidURIError unless ELASTICSEARCH_URL =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/
22
+
23
+ def client
24
+ @client ||= Elasticsearch::Client.new(
25
+ host: ELASTICSEARCH_URL,
26
+ user: 'elastic',
27
+ password: 'changeme'
28
+ )
29
+ end
@@ -14,20 +14,10 @@
14
14
  # KIND, either express or implied. See the License for the
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
- ELASTICSEARCH_URL = ENV['TEST_ES_SERVER'] || "http://localhost:#{(ENV['PORT'] || 9200)}"
18
- raise URI::InvalidURIError unless ELASTICSEARCH_URL =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/
19
-
20
- require 'spec_helper'
17
+ require_relative 'helpers_spec_helper'
21
18
  require 'elasticsearch/helpers/scroll_helper'
22
19
 
23
20
  context 'Elasticsearch client helpers' do
24
- let(:client) do
25
- Elasticsearch::Client.new(
26
- host: ELASTICSEARCH_URL,
27
- user: 'elastic',
28
- password: 'changeme'
29
- )
30
- end
31
21
  let(:index) { 'books' }
32
22
  let(:body) { { size: 12, query: { match_all: {} } } }
33
23
  let(:scroll_helper) { Elasticsearch::Helpers::ScrollHelper.new(client, index, body) }
@@ -0,0 +1,55 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ if ENV['TEST_WITH_OTEL'] == 'true'
19
+ ELASTICSEARCH_URL = ENV['TEST_ES_SERVER'] || "http://localhost:#{(ENV['PORT'] || 9200)}"
20
+ raise URI::InvalidURIError unless ELASTICSEARCH_URL =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/
21
+
22
+ require 'spec_helper'
23
+
24
+ context 'OpenTelemetry' do
25
+ let(:exporter) { EXPORTER }
26
+ before { exporter.reset }
27
+ after { exporter.reset }
28
+ let(:span) { exporter.finished_spans[0] }
29
+
30
+ let(:client) do
31
+ Elasticsearch::Client.new(
32
+ host: ELASTICSEARCH_URL,
33
+ user: 'elastic',
34
+ password: 'changeme'
35
+ )
36
+ end
37
+
38
+ after do
39
+ client.delete(index: 'myindex', id: 1); rescue
40
+ end
41
+
42
+ context 'when a request is instrumented' do
43
+ it 'sets the span name to the endpoint id' do
44
+ client.search(body: { query: { match: {a: 1} } })
45
+ expect(span.name).to eq 'search'
46
+ end
47
+
48
+ it 'sets the path parts' do
49
+ client.index(index: 'myindex', id: 1, body: { title: 'Test' })
50
+ expect(span.attributes['db.elasticsearch.path_parts.index']).to eq 'myindex'
51
+ expect(span.attributes['db.elasticsearch.path_parts.id']).to eq 1
52
+ end
53
+ end
54
+ end
55
+ end
data/spec/spec_helper.rb CHANGED
@@ -29,3 +29,15 @@ end
29
29
  def jruby?
30
30
  defined?(JRUBY_VERSION)
31
31
  end
32
+
33
+ if ENV['TEST_WITH_OTEL'] == 'true'
34
+ require 'opentelemetry-sdk'
35
+ EXPORTER = OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new
36
+ span_processor = OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(EXPORTER)
37
+
38
+ OpenTelemetry::SDK.configure do |c|
39
+ c.error_handler = ->(exception:, message:) { raise(exception || message) }
40
+ c.logger = Logger.new($stderr, level: ENV.fetch('OTEL_LOG_LEVEL', 'fatal').to_sym)
41
+ c.add_span_processor span_processor
42
+ end
43
+ end
@@ -29,7 +29,7 @@ describe Elasticsearch::Client do
29
29
  it 'uses x-opaque-id on a request' do
30
30
  client.search(opaque_id: '12345')
31
31
  expect(transport).to have_received(:perform_request)
32
- .with('GET', '_search', {}, nil, { 'X-Opaque-Id' => '12345' })
32
+ .with('GET', '_search', {}, nil, { 'X-Opaque-Id' => '12345' }, {:endpoint=>"search"})
33
33
  end
34
34
  end
35
35
 
@@ -42,7 +42,7 @@ describe Elasticsearch::Client do
42
42
  it 'uses x-opaque-id on a request' do
43
43
  expect { client.search(opaque_id: '12345') }.not_to raise_error
44
44
  expect(transport).to have_received(:perform_request)
45
- .with('GET', '_search', {}, nil, { 'X-Opaque-Id' => 'elastic_cloud12345' })
45
+ .with('GET', '_search', {}, nil, { 'X-Opaque-Id' => 'elastic_cloud12345' }, {:endpoint=>"search"})
46
46
  end
47
47
  end
48
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.12.2
4
+ version: 8.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic Client Library Maintainers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-06 00:00:00.000000000 Z
11
+ date: 2024-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: elastic-transport
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 8.12.2
33
+ version: 8.13.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 8.12.2
40
+ version: 8.13.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: base64
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: byebug
70
+ name: debug
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -214,12 +214,16 @@ files:
214
214
  - lib/elasticsearch-ruby.rb
215
215
  - lib/elasticsearch.rb
216
216
  - lib/elasticsearch/helpers/bulk_helper.rb
217
+ - lib/elasticsearch/helpers/esql_helper.rb
217
218
  - lib/elasticsearch/helpers/scroll_helper.rb
218
219
  - lib/elasticsearch/version.rb
219
220
  - spec/integration/characters_escaping_spec.rb
220
221
  - spec/integration/client_integration_spec.rb
221
222
  - spec/integration/helpers/bulk_helper_spec.rb
223
+ - spec/integration/helpers/esql_helper_spec.rb
224
+ - spec/integration/helpers/helpers_spec_helper.rb
222
225
  - spec/integration/helpers/scroll_helper_spec.rb
226
+ - spec/integration/opentelemetry_spec.rb
223
227
  - spec/spec_helper.rb
224
228
  - spec/unit/api_key_spec.rb
225
229
  - spec/unit/cloud_credentials_spec.rb
@@ -261,7 +265,10 @@ test_files:
261
265
  - spec/integration/characters_escaping_spec.rb
262
266
  - spec/integration/client_integration_spec.rb
263
267
  - spec/integration/helpers/bulk_helper_spec.rb
268
+ - spec/integration/helpers/esql_helper_spec.rb
269
+ - spec/integration/helpers/helpers_spec_helper.rb
264
270
  - spec/integration/helpers/scroll_helper_spec.rb
271
+ - spec/integration/opentelemetry_spec.rb
265
272
  - spec/spec_helper.rb
266
273
  - spec/unit/api_key_spec.rb
267
274
  - spec/unit/cloud_credentials_spec.rb