elasticsearch 8.16.0 → 9.2.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: 32cd6c6f02b68199e9e021fc628d7336525284f7111dda9dc82f1cd9600447f1
4
- data.tar.gz: a7f3660149d1bdab70ce54402bacd81d715f470206adec898908d54e71879c9c
3
+ metadata.gz: 416eb19b60e9921f68c5ee015c548bcec83efe0bb5a8e8bbde764354441b6f40
4
+ data.tar.gz: 84ab9e3bb36db5edb709df7b92212d1a5cfb7180dd79fab01ee62c1380898ad4
5
5
  SHA512:
6
- metadata.gz: 62e4e89c10b02281131710598fdc483c8e10ddb6d927b5ce311a1a44043b9dbf2bbd13e542281113a45d066a5a85522960acc2736672bb4d853151fd07ce06fa
7
- data.tar.gz: cef1f6fb061b12efa6ca0bc60ed334d57bd17b8f2d64b86eae205743e5b51a631beb44b1391d99590336c79eff175b44b3d406baeb23dbbb4ece6b42aa94c240
6
+ metadata.gz: 779e20047d61128d03ca19651c00027f380d3e3bbbecfd96eeb917d104b4a7975b427904330934720259c3bc76e74c6f8e3f44989c039dff1866f16e4c469359
7
+ data.tar.gz: b9f0c986fb7d5e6562d6fc75b792c61d4d88da2155f27f87ac2beba7f445fba1014ecd088ff2597f48a9a2e2d02a6224ff15115a5f97c091e9cae53b0d980d70
@@ -15,7 +15,7 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- lib = File.expand_path('../lib', __FILE__)
18
+ lib = File.expand_path('lib', __dir__)
19
19
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
20
20
  require 'elasticsearch/version'
21
21
 
@@ -33,24 +33,26 @@ Gem::Specification.new do |s|
33
33
  'source_code_uri' => 'https://github.com/elastic/elasticsearch-ruby/tree/main',
34
34
  'bug_tracker_uri' => 'https://github.com/elastic/elasticsearch-ruby/issues'
35
35
  }
36
- s.files = `git ls-files`.split($/)
36
+ s.files = `git ls-files`.split($/).reject do |file|
37
+ file.match(/^spec\/|^Gemfile|^Rakefile/)
38
+ end
39
+
37
40
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
38
41
  s.executables << 'elastic_ruby_console'
39
- s.test_files = s.files.grep(%r{^(test|spec|features)/})
40
42
  s.require_paths = ['lib']
41
43
  s.bindir = 'bin'
42
44
 
43
45
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
44
46
  s.rdoc_options = ['--charset=UTF-8']
45
47
 
46
- s.required_ruby_version = '>= 2.5'
47
-
48
+ s.required_ruby_version = '>= 2.6' # For compatibility with JRuby 9.3
49
+ s.add_dependency 'elasticsearch-api', '9.2.0'
48
50
  s.add_dependency 'elastic-transport', '~> 8.3'
49
- s.add_dependency 'elasticsearch-api', '8.16.0'
50
51
 
51
52
  s.add_development_dependency 'base64'
52
53
  s.add_development_dependency 'bundler'
53
54
  s.add_development_dependency 'debug' unless defined?(JRUBY_VERSION)
55
+ s.add_development_dependency 'ostruct'
54
56
  s.add_development_dependency 'pry'
55
57
  s.add_development_dependency 'rake'
56
58
  s.add_development_dependency 'require-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
@@ -43,12 +43,8 @@ module Elasticsearch
43
43
  # @yieldparam document [Hash] yields a document found in the search hits.
44
44
  #
45
45
  def each(&block)
46
- @docs = []
47
- @scroll_id = nil
48
- refresh_docs
49
- for doc in @docs do
50
- refresh_docs
51
- yield doc
46
+ until (docs = results).empty?
47
+ docs.each(&block)
52
48
  end
53
49
  clear
54
50
  end
@@ -70,17 +66,11 @@ module Elasticsearch
70
66
  #
71
67
  def clear
72
68
  @client.clear_scroll(body: { scroll_id: @scroll_id }) if @scroll_id
73
- @docs = []
69
+ @scroll_id = nil
74
70
  end
75
71
 
76
72
  private
77
73
 
78
- def refresh_docs
79
- @docs ||= []
80
- @docs << results
81
- @docs.flatten!
82
- end
83
-
84
74
  def initial_search
85
75
  response = @client.search(index: @index, scroll: @scroll, body: @body)
86
76
  @scroll_id = response['_scroll_id']
@@ -88,7 +78,7 @@ module Elasticsearch
88
78
  end
89
79
 
90
80
  def scroll_request
91
- @client.scroll(body: {scroll: @scroll, scroll_id: @scroll_id})['hits']['hits']
81
+ @client.scroll(body: { scroll: @scroll, scroll_id: @scroll_id })['hits']['hits']
92
82
  end
93
83
  end
94
84
  end
@@ -16,5 +16,5 @@
16
16
  # under the License.
17
17
 
18
18
  module Elasticsearch
19
- VERSION = '8.16.0'.freeze
19
+ VERSION = '9.2.0'.freeze
20
20
  end
data/lib/elasticsearch.rb CHANGED
@@ -37,8 +37,9 @@ module Elasticsearch
37
37
  #
38
38
  # @param [Hash] arguments - initializer arguments
39
39
  # @option arguments [String] :cloud_id - The Cloud ID to connect to Elastic Cloud
40
- # @option arguments [String, Hash] :api_key Use API Key Authentication, either the base64 encoding of `id` and `api_key`
41
- # joined by a colon as a String, or a hash with the `id` and `api_key` values.
40
+ # @option arguments [String, Hash] :api_key Use API Key Authentication, either the base64 encoding of `id` and
41
+ # `api_key` joined by a colon as a String, or a hash with the `id` and
42
+ # `api_key` values.
42
43
  # @option arguments [String] :opaque_id_prefix set a prefix for X-Opaque-Id when initializing the client.
43
44
  # This will be prepended to the id you set before each request
44
45
  # if you're using X-Opaque-Id
@@ -51,6 +52,7 @@ module Elasticsearch
51
52
  api_key(arguments) if arguments[:api_key]
52
53
  setup_cloud(arguments) if arguments[:cloud_id]
53
54
  set_user_agent!(arguments) unless sent_user_agent?(arguments)
55
+ set_content_type!(arguments)
54
56
  @transport = Elastic::Transport::Client.new(arguments, &block)
55
57
  end
56
58
 
@@ -65,10 +67,10 @@ module Elasticsearch
65
67
  opaque_id = @opaque_id_prefix ? "#{@opaque_id_prefix}#{opaque_id}" : opaque_id
66
68
  args[4] = headers.merge('X-Opaque-Id' => opaque_id)
67
69
  end
68
- unless @verified
69
- verify_elasticsearch(*args, &block)
70
- else
70
+ if @verified
71
71
  @transport.perform_request(*args, &block)
72
+ else
73
+ verify_elasticsearch(*args, &block)
72
74
  end
73
75
  else
74
76
  @transport.send(name, *args, &block)
@@ -101,6 +103,7 @@ module Elasticsearch
101
103
  raise e
102
104
  end
103
105
  raise Elasticsearch::UnsupportedProductError unless response.headers['x-elastic-product'] == 'Elasticsearch'
106
+
104
107
  @verified = true
105
108
  response
106
109
  end
@@ -173,9 +176,25 @@ module Elasticsearch
173
176
  if RbConfig::CONFIG && RbConfig::CONFIG['host_os']
174
177
  user_agent << "#{RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase} #{RbConfig::CONFIG['target_cpu']}"
175
178
  end
179
+ set_header({ user_agent: user_agent.join('; ') }, arguments)
180
+ end
181
+
182
+ def set_content_type!(arguments)
183
+ headers = {}
184
+ user_headers = arguments&.[](:transport_options)&.[](:headers)
185
+ unless user_headers&.keys&.detect { |h| h =~ /content-?_?type/ }
186
+ headers['content-type'] = 'application/vnd.elasticsearch+json; compatible-with=9'
187
+ end
188
+ unless user_headers&.keys&.detect { |h| h =~ /accept/ }
189
+ headers['accept'] = 'application/vnd.elasticsearch+json; compatible-with=9'
190
+ end
191
+ set_header(headers, arguments) unless headers.empty?
192
+ end
193
+
194
+ def set_header(header, arguments)
176
195
  arguments[:transport_options] ||= {}
177
196
  arguments[:transport_options][:headers] ||= {}
178
- arguments[:transport_options][:headers].merge!({ user_agent: user_agent.join('; ')})
197
+ arguments[:transport_options][:headers].merge!(header)
179
198
  end
180
199
  end
181
200
 
metadata CHANGED
@@ -1,15 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.16.0
4
+ version: 9.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic Client Library Maintainers
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-11-12 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: elasticsearch-api
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - '='
17
+ - !ruby/object:Gem::Version
18
+ version: 9.2.0
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - '='
24
+ - !ruby/object:Gem::Version
25
+ version: 9.2.0
13
26
  - !ruby/object:Gem::Dependency
14
27
  name: elastic-transport
15
28
  requirement: !ruby/object:Gem::Requirement
@@ -25,21 +38,21 @@ dependencies:
25
38
  - !ruby/object:Gem::Version
26
39
  version: '8.3'
27
40
  - !ruby/object:Gem::Dependency
28
- name: elasticsearch-api
41
+ name: base64
29
42
  requirement: !ruby/object:Gem::Requirement
30
43
  requirements:
31
- - - '='
44
+ - - ">="
32
45
  - !ruby/object:Gem::Version
33
- version: 8.16.0
34
- type: :runtime
46
+ version: '0'
47
+ type: :development
35
48
  prerelease: false
36
49
  version_requirements: !ruby/object:Gem::Requirement
37
50
  requirements:
38
- - - '='
51
+ - - ">="
39
52
  - !ruby/object:Gem::Version
40
- version: 8.16.0
53
+ version: '0'
41
54
  - !ruby/object:Gem::Dependency
42
- name: base64
55
+ name: bundler
43
56
  requirement: !ruby/object:Gem::Requirement
44
57
  requirements:
45
58
  - - ">="
@@ -53,7 +66,7 @@ dependencies:
53
66
  - !ruby/object:Gem::Version
54
67
  version: '0'
55
68
  - !ruby/object:Gem::Dependency
56
- name: bundler
69
+ name: debug
57
70
  requirement: !ruby/object:Gem::Requirement
58
71
  requirements:
59
72
  - - ">="
@@ -67,7 +80,7 @@ dependencies:
67
80
  - !ruby/object:Gem::Version
68
81
  version: '0'
69
82
  - !ruby/object:Gem::Dependency
70
- name: debug
83
+ name: ostruct
71
84
  requirement: !ruby/object:Gem::Requirement
72
85
  requirements:
73
86
  - - ">="
@@ -201,14 +214,12 @@ executables:
201
214
  - elastic_ruby_console
202
215
  extensions: []
203
216
  extra_rdoc_files:
204
- - README.md
205
217
  - LICENSE.txt
218
+ - README.md
206
219
  files:
207
220
  - ".gitignore"
208
- - Gemfile
209
221
  - LICENSE.txt
210
222
  - README.md
211
- - Rakefile
212
223
  - bin/elastic_ruby_console
213
224
  - elasticsearch.gemspec
214
225
  - lib/elasticsearch-ruby.rb
@@ -217,22 +228,6 @@ files:
217
228
  - lib/elasticsearch/helpers/esql_helper.rb
218
229
  - lib/elasticsearch/helpers/scroll_helper.rb
219
230
  - lib/elasticsearch/version.rb
220
- - spec/integration/characters_escaping_spec.rb
221
- - spec/integration/client_integration_spec.rb
222
- - spec/integration/helpers/bulk_helper_spec.rb
223
- - spec/integration/helpers/esql_helper_spec.rb
224
- - spec/integration/helpers/helpers_spec_helper.rb
225
- - spec/integration/helpers/scroll_helper_spec.rb
226
- - spec/integration/opentelemetry_spec.rb
227
- - spec/spec_helper.rb
228
- - spec/unit/api_key_spec.rb
229
- - spec/unit/cloud_credentials_spec.rb
230
- - spec/unit/custom_transport_implementation_spec.rb
231
- - spec/unit/elasticsearch_product_validation_spec.rb
232
- - spec/unit/headers_spec.rb
233
- - spec/unit/opaque_id_spec.rb
234
- - spec/unit/user_agent_spec.rb
235
- - spec/unit/wrapper_gem_spec.rb
236
231
  homepage: https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/index.html
237
232
  licenses:
238
233
  - Apache-2.0
@@ -241,7 +236,6 @@ metadata:
241
236
  changelog_uri: https://github.com/elastic/elasticsearch-ruby/blob/main/CHANGELOG.md
242
237
  source_code_uri: https://github.com/elastic/elasticsearch-ruby/tree/main
243
238
  bug_tracker_uri: https://github.com/elastic/elasticsearch-ruby/issues
244
- post_install_message:
245
239
  rdoc_options:
246
240
  - "--charset=UTF-8"
247
241
  require_paths:
@@ -250,31 +244,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
250
244
  requirements:
251
245
  - - ">="
252
246
  - !ruby/object:Gem::Version
253
- version: '2.5'
247
+ version: '2.6'
254
248
  required_rubygems_version: !ruby/object:Gem::Requirement
255
249
  requirements:
256
250
  - - ">="
257
251
  - !ruby/object:Gem::Version
258
252
  version: '0'
259
253
  requirements: []
260
- rubygems_version: 3.5.20
261
- signing_key:
254
+ rubygems_version: 3.6.9
262
255
  specification_version: 4
263
256
  summary: Ruby integrations for Elasticsearch
264
- test_files:
265
- - spec/integration/characters_escaping_spec.rb
266
- - spec/integration/client_integration_spec.rb
267
- - spec/integration/helpers/bulk_helper_spec.rb
268
- - spec/integration/helpers/esql_helper_spec.rb
269
- - spec/integration/helpers/helpers_spec_helper.rb
270
- - spec/integration/helpers/scroll_helper_spec.rb
271
- - spec/integration/opentelemetry_spec.rb
272
- - spec/spec_helper.rb
273
- - spec/unit/api_key_spec.rb
274
- - spec/unit/cloud_credentials_spec.rb
275
- - spec/unit/custom_transport_implementation_spec.rb
276
- - spec/unit/elasticsearch_product_validation_spec.rb
277
- - spec/unit/headers_spec.rb
278
- - spec/unit/opaque_id_spec.rb
279
- - spec/unit/user_agent_spec.rb
280
- - spec/unit/wrapper_gem_spec.rb
257
+ test_files: []
data/Gemfile DELETED
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Licensed to Elasticsearch B.V. under one or more contributor
4
- # license agreements. See the NOTICE file distributed with
5
- # this work for additional information regarding copyright
6
- # ownership. Elasticsearch B.V. licenses this file to you under
7
- # the Apache License, Version 2.0 (the "License"); you may
8
- # not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
-
20
- source 'https://rubygems.org'
21
-
22
- # Specify your gem's dependencies in elasticsearch.gemspec
23
- gemspec
24
-
25
- if File.exist? File.expand_path('../elasticsearch-api/elasticsearch-api.gemspec', __dir__)
26
- gem 'elasticsearch-api', path: File.expand_path('../elasticsearch-api', __dir__), require: false
27
- end
28
-
29
- if ENV['TRANSPORT_VERSION'] == 'main'
30
- gem 'elastic-transport', git: 'https://github.com/elastic/elastic-transport-ruby.git', branch: 'main'
31
- end
32
-
33
- if RUBY_VERSION >= '3.0'
34
- gem 'opentelemetry-sdk', require: false
35
- end
data/Rakefile DELETED
@@ -1,54 +0,0 @@
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 'bundler/gem_tasks'
19
-
20
- task(:default) { system 'rake --tasks' }
21
-
22
- desc 'Run unit tests'
23
- task test: 'test:spec'
24
-
25
- # ----- Test tasks ------------------------------------------------------------
26
- require 'rspec/core/rake_task'
27
-
28
- namespace :test do
29
- desc 'Wait for Elasticsearch to be in a green state'
30
- task :wait_for_green do
31
- sh '../scripts/wait-cluster.sh'
32
- end
33
-
34
- RSpec::Core::RakeTask.new(:integration) do |t|
35
- t.pattern = 'spec/integration/**{,/*/**}/*_spec.rb'
36
- end
37
-
38
- RSpec::Core::RakeTask.new(:unit) do |t|
39
- t.pattern = 'spec/unit/**{,/*/**}/*_spec.rb'
40
- end
41
-
42
- desc 'Run unit and integration tests'
43
- task :all do
44
- Rake::Task['test:unit'].invoke
45
- Rake::Task['test:integration'].invoke
46
- end
47
- end
48
-
49
- # ----- Documentation tasks ---------------------------------------------------
50
-
51
- require 'yard'
52
- YARD::Rake::YardocTask.new(:doc) do |t|
53
- t.options = %w| --embed-mixins --markup=markdown |
54
- end
@@ -1,96 +0,0 @@
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
- require 'uri'
20
-
21
- ELASTICSEARCH_URL = ENV['TEST_ES_SERVER'] || "http://localhost:#{(ENV['PORT'] || 9200)}"
22
- raise URI::InvalidURIError unless ELASTICSEARCH_URL =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/
23
-
24
- context 'Elasticsearch client' do
25
- let(:client) do
26
- Elasticsearch::Client.new(host: ELASTICSEARCH_URL, user: 'elastic', password: 'changeme')
27
- end
28
- let(:index) { 'tvs' }
29
-
30
- after do
31
- client.indices.delete(index: index)
32
- end
33
-
34
- context 'escaping spaces in ids' do
35
- it 'escapes spaces for id when using index' do
36
- response = client.index(index: index, id: 'a test 1', body: { name: 'A test 1' }, refresh: true)
37
- expect(response.body['_id']).to eq 'a test 1'
38
-
39
- response = client.search(index: index)
40
- expect(response.body['hits']['hits'].first['_id']).to eq 'a test 1'
41
-
42
- # Raises exception, _id is unrecognized
43
- expect do
44
- client.index(index: index, _id: 'a test 2', body: { name: 'A test 2' })
45
- end.to raise_exception Elastic::Transport::Transport::Errors::BadRequest
46
-
47
- # Raises exception, id is a query parameter
48
- expect do
49
- client.index(index: index, body: { name: 'A test 3', _id: 'a test 3' })
50
- end.to raise_exception Elastic::Transport::Transport::Errors::BadRequest
51
- end
52
-
53
- it 'escapes spaces for id when using create' do
54
- # Works with create
55
- response = client.create(index: index, id: 'a test 4', body: { name: 'A test 4' })
56
- expect(response.body['_id']).to eq 'a test 4'
57
- end
58
-
59
- it 'escapes spaces for id when using bulk' do
60
- body = [
61
- { create: { _index: index, _id: 'a test 5', data: { name: 'A test 5' } } }
62
- ]
63
- expect(client.bulk(body: body, refresh: true).status).to eq 200
64
-
65
- response = client.search(index: index)
66
- expect(
67
- response.body['hits']['hits'].select { |a| a['_id'] == 'a test 5' }.size
68
- ).to eq 1
69
- end
70
- end
71
-
72
- context 'it doesnae escape plus signs in id' do
73
- it 'escapes spaces for id when using index' do
74
- response = client.index(index: index, id: 'a+test+1', body: { name: 'A test 1' })
75
- expect(response.body['_id']).to eq 'a+test+1'
76
- end
77
-
78
- it 'escapes spaces for id when using create' do
79
- # Works with create
80
- response = client.create(index: index, id: 'a+test+2', body: { name: 'A test 2' })
81
- expect(response.body['_id']).to eq 'a+test+2'
82
- end
83
-
84
- it 'escapes spaces for id when using bulk' do
85
- body = [
86
- { create: { _index: index, _id: 'a+test+3', data: { name: 'A test 3' } } }
87
- ]
88
- expect(client.bulk(body: body, refresh: true).status).to eq 200
89
-
90
- response = client.search(index: index)
91
- expect(
92
- response.body['hits']['hits'].select { |a| a['_id'] == 'a+test+3' }.size
93
- ).to eq 1
94
- end
95
- end
96
- end
@@ -1,64 +0,0 @@
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
- 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'
21
- require 'logger'
22
- require 'uri'
23
-
24
- context 'Elasticsearch client' do
25
- let(:logger) { Logger.new($stderr) }
26
-
27
- let(:client) do
28
- Elasticsearch::Client.new(
29
- host: ELASTICSEARCH_URL,
30
- logger: logger,
31
- user: 'elastic',
32
- password: 'changeme'
33
- )
34
- end
35
-
36
- context 'Integrates with elasticsearch API' do
37
- it 'should perform the API methods' do
38
- expect do
39
- # Index a document
40
- client.index(index: 'test-index', id: '1', body: { title: 'Test' })
41
-
42
- # Refresh the index
43
- client.indices.refresh(index: 'test-index')
44
-
45
- # Search
46
- response = client.search(index: 'test-index', body: { query: { match: { title: 'test' } } })
47
-
48
- expect(response['hits']['total']['value']).to eq 1
49
- expect(response['hits']['hits'][0]['_source']['title']).to eq 'Test'
50
-
51
- # Delete the index
52
- client.indices.delete(index: 'test-index')
53
- end.not_to raise_error
54
- end
55
- end
56
-
57
- context 'Reports the right meta header' do
58
- it 'Reports es service name and gem version' do
59
- headers = client.transport.connections.first.connection.headers
60
- version = Class.new.extend(Elastic::Transport::MetaHeader).send(:client_meta_version, Elasticsearch::VERSION)
61
- expect(headers['x-elastic-client-meta']).to match /^es=#{version}/
62
- end
63
- end
64
- end