elasticsearch 8.18.0 → 9.0.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: ffbcb26ce9f617a221824e96f4c0e35d0527421ec96a91bfb23d24505ef40179
4
- data.tar.gz: bbd6ef3916794c4bd36fa01939bf5ae6e655348405afaa5625000be63add8baa
3
+ metadata.gz: 26ff9ee984327ed517e9aa27be77fd79247e23b0e3ccd080c6c091e496b0b49d
4
+ data.tar.gz: 2f5a3f30af1ad0dc0f4d568bcc7d89e8ad1bfc16469ee5672dcc57a81687cc63
5
5
  SHA512:
6
- metadata.gz: 742d28e13b8c5ee4c48d8b783e13b0abcc57848f1cf128dbf363b6c11c54aa6882a0421785f60b1f295f547c41abf36663e342b210347e9ff56bc5c363d0575e
7
- data.tar.gz: 94fd5a49a98f22d11feb427f78fd6319a8a856a0bcb8286408243e907d041213cabcacfde04ebb92f42da887d0f152842ec03e3e63304eeb61a1d9d8b42eea34
6
+ metadata.gz: 5588870792cefa5145db01cc7e1bbc04d1d90f69af0f10db72c83041209c5d9e6f873e44552745a646af27ca679260a92e3dcedce24d57d827543e471e9803e7
7
+ data.tar.gz: '0817be29b78c69cac36d09fe454857916df101b685d0d8e544ecaf0cc76b36e8f0e83e7c504fd7cf5f2d394b830ae1136d225786d5c9a6cddc623f3d0e3c5b79'
@@ -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,20 +33,21 @@ 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.0.0'
48
50
  s.add_dependency 'elastic-transport', '~> 8.3'
49
- s.add_dependency 'elasticsearch-api', '8.18.0'
50
51
 
51
52
  s.add_development_dependency 'base64'
52
53
  s.add_development_dependency 'bundler'
@@ -16,5 +16,5 @@
16
16
  # under the License.
17
17
 
18
18
  module Elasticsearch
19
- VERSION = '8.18.0'.freeze
19
+ VERSION = '9.0.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
@@ -65,10 +66,10 @@ module Elasticsearch
65
66
  opaque_id = @opaque_id_prefix ? "#{@opaque_id_prefix}#{opaque_id}" : opaque_id
66
67
  args[4] = headers.merge('X-Opaque-Id' => opaque_id)
67
68
  end
68
- unless @verified
69
- verify_elasticsearch(*args, &block)
70
- else
69
+ if @verified
71
70
  @transport.perform_request(*args, &block)
71
+ else
72
+ verify_elasticsearch(*args, &block)
72
73
  end
73
74
  else
74
75
  @transport.send(name, *args, &block)
@@ -101,6 +102,7 @@ module Elasticsearch
101
102
  raise e
102
103
  end
103
104
  raise Elasticsearch::UnsupportedProductError unless response.headers['x-elastic-product'] == 'Elasticsearch'
105
+
104
106
  @verified = true
105
107
  response
106
108
  end
@@ -175,7 +177,7 @@ module Elasticsearch
175
177
  end
176
178
  arguments[:transport_options] ||= {}
177
179
  arguments[:transport_options][:headers] ||= {}
178
- arguments[:transport_options][:headers].merge!({ user_agent: user_agent.join('; ')})
180
+ arguments[:transport_options][:headers].merge!({ user_agent: user_agent.join('; ') })
179
181
  end
180
182
  end
181
183
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.18.0
4
+ version: 9.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic Client Library Maintainers
@@ -10,33 +10,33 @@ cert_chain: []
10
10
  date: 2025-04-15 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
- name: elastic-transport
13
+ name: elasticsearch-api
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - "~>"
16
+ - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: '8.3'
18
+ version: 9.0.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
- - - "~>"
23
+ - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: '8.3'
25
+ version: 9.0.0
26
26
  - !ruby/object:Gem::Dependency
27
- name: elasticsearch-api
27
+ name: elastic-transport
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
- - - '='
30
+ - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: 8.18.0
32
+ version: '8.3'
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - '='
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 8.18.0
39
+ version: '8.3'
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: base64
42
42
  requirement: !ruby/object:Gem::Requirement
@@ -204,10 +204,8 @@ extra_rdoc_files:
204
204
  - LICENSE.txt
205
205
  files:
206
206
  - ".gitignore"
207
- - Gemfile
208
207
  - LICENSE.txt
209
208
  - README.md
210
- - Rakefile
211
209
  - bin/elastic_ruby_console
212
210
  - elasticsearch.gemspec
213
211
  - lib/elasticsearch-ruby.rb
@@ -216,22 +214,6 @@ files:
216
214
  - lib/elasticsearch/helpers/esql_helper.rb
217
215
  - lib/elasticsearch/helpers/scroll_helper.rb
218
216
  - lib/elasticsearch/version.rb
219
- - spec/integration/characters_escaping_spec.rb
220
- - spec/integration/client_integration_spec.rb
221
- - spec/integration/helpers/bulk_helper_spec.rb
222
- - spec/integration/helpers/esql_helper_spec.rb
223
- - spec/integration/helpers/helpers_spec_helper.rb
224
- - spec/integration/helpers/scroll_helper_spec.rb
225
- - spec/integration/opentelemetry_spec.rb
226
- - spec/spec_helper.rb
227
- - spec/unit/api_key_spec.rb
228
- - spec/unit/cloud_credentials_spec.rb
229
- - spec/unit/custom_transport_implementation_spec.rb
230
- - spec/unit/elasticsearch_product_validation_spec.rb
231
- - spec/unit/headers_spec.rb
232
- - spec/unit/opaque_id_spec.rb
233
- - spec/unit/user_agent_spec.rb
234
- - spec/unit/wrapper_gem_spec.rb
235
217
  homepage: https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/index.html
236
218
  licenses:
237
219
  - Apache-2.0
@@ -248,7 +230,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
248
230
  requirements:
249
231
  - - ">="
250
232
  - !ruby/object:Gem::Version
251
- version: '2.5'
233
+ version: '2.6'
252
234
  required_rubygems_version: !ruby/object:Gem::Requirement
253
235
  requirements:
254
236
  - - ">="
@@ -258,20 +240,4 @@ requirements: []
258
240
  rubygems_version: 3.6.2
259
241
  specification_version: 4
260
242
  summary: Ruby integrations for Elasticsearch
261
- test_files:
262
- - spec/integration/characters_escaping_spec.rb
263
- - spec/integration/client_integration_spec.rb
264
- - spec/integration/helpers/bulk_helper_spec.rb
265
- - spec/integration/helpers/esql_helper_spec.rb
266
- - spec/integration/helpers/helpers_spec_helper.rb
267
- - spec/integration/helpers/scroll_helper_spec.rb
268
- - spec/integration/opentelemetry_spec.rb
269
- - spec/spec_helper.rb
270
- - spec/unit/api_key_spec.rb
271
- - spec/unit/cloud_credentials_spec.rb
272
- - spec/unit/custom_transport_implementation_spec.rb
273
- - spec/unit/elasticsearch_product_validation_spec.rb
274
- - spec/unit/headers_spec.rb
275
- - spec/unit/opaque_id_spec.rb
276
- - spec/unit/user_agent_spec.rb
277
- - spec/unit/wrapper_gem_spec.rb
243
+ 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
@@ -1,206 +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
- require_relative 'helpers_spec_helper'
18
- require 'elasticsearch/helpers/bulk_helper'
19
- require 'tempfile'
20
-
21
- context 'Elasticsearch client helpers' do
22
- context 'Bulk helper' do
23
- let(:index) { 'bulk_animals' }
24
- let(:index_slice) { 'bulk_animals_slice' }
25
- let(:params) { { refresh: 'wait_for' } }
26
- let(:bulk_helper) { Elasticsearch::Helpers::BulkHelper.new(client, index, params) }
27
- let(:docs) do
28
- [
29
- { scientific_name: 'Lama guanicoe', name:'Guanaco' },
30
- { scientific_name: 'Tayassu pecari', name:'White-lipped peccary' },
31
- { scientific_name: 'Snycerus caffer', name:'Buffalo, african' },
32
- { scientific_name: 'Coluber constrictor', name:'Snake, racer' },
33
- { scientific_name: 'Thalasseus maximus', name:'Royal tern' },
34
- { scientific_name: 'Centrocercus urophasianus', name:'Hen, sage' },
35
- { scientific_name: 'Sitta canadensis', name:'Nuthatch, red-breasted' },
36
- { scientific_name: 'Aegypius tracheliotus', name:'Vulture, lappet-faced' },
37
- { scientific_name: 'Bucephala clangula', name:'Common goldeneye' },
38
- { scientific_name: 'Felis pardalis', name:'Ocelot' }
39
- ]
40
- end
41
-
42
- after do
43
- client.indices.delete(index: index, ignore: 404)
44
- client.indices.delete(index: index_slice, ignore: 404)
45
- end
46
-
47
- it 'Ingests documents' do
48
- response = bulk_helper.ingest(docs)
49
- expect(response).to be_an_instance_of Elasticsearch::API::Response
50
- expect(response.status).to eq(200)
51
- expect(response['items'].map { |a| a['index']['status'] }.uniq.first).to eq 201
52
- end
53
-
54
- it 'Updates documents' do
55
- docs = [
56
- { scientific_name: 'Otocyon megalotos', name: 'Bat-eared fox' },
57
- { scientific_name: 'Herpestes javanicus', name: 'Small Indian mongoose' }
58
- ]
59
- bulk_helper.ingest(docs)
60
- # Get the ingested documents, add id and modify them to update them:
61
- animals = client.search(index: index)['hits']['hits']
62
- # Add id to each doc
63
- docs = animals.map { |animal| animal['_source'].merge({'id' => animal['_id'] }) }
64
- docs.map { |doc| doc['scientific_name'].upcase! }
65
- response = bulk_helper.update(docs)
66
- expect(response.status).to eq(200)
67
- expect(response['items'].map { |i| i['update']['result'] }.uniq.first).to eq('updated')
68
- end
69
-
70
- it 'Deletes documents' do
71
- response = bulk_helper.ingest(docs)
72
- ids = response.body['items'].map { |a| a['index']['_id'] }
73
- response = bulk_helper.delete(ids)
74
- expect(response.status).to eq 200
75
- expect(response['items'].map { |item| item['delete']['result'] }.uniq.first).to eq('deleted')
76
- expect(client.count(index: index)['count']).to eq(0)
77
- end
78
-
79
- it 'Ingests documents and yields response and docs' do
80
- slice = 2
81
- bulk_helper = Elasticsearch::Helpers::BulkHelper.new(client, index_slice, params)
82
- response = bulk_helper.ingest(docs, {slice: slice}) do |response, docs|
83
- expect(response).to be_an_instance_of Elasticsearch::API::Response
84
- expect(docs.count).to eq slice
85
- end
86
- response = client.search(index: index_slice, size: 200)
87
- expect(response['hits']['hits'].map { |a| a['_source'].transform_keys(&:to_sym) }).to eq docs
88
- end
89
-
90
- context 'JSON File helper' do
91
- let(:file) { Tempfile.new('test-data.json') }
92
- let(:json) do
93
- json = <<~JSON
94
- [
95
- {
96
- "character_name": "Anallese Lonie",
97
- "species": "mouse",
98
- "catchphrase": "Seamless regional definition",
99
- "favorite_food": "pizza"
100
- },
101
- {
102
- "character_name": "Janey Davidovsky",
103
- "species": "cat",
104
- "catchphrase": "Down-sized responsive pricing structure",
105
- "favorite_food": "pizza"
106
- },
107
- {
108
- "character_name": "Morse Mountford",
109
- "species": "cat",
110
- "catchphrase": "Ameliorated modular data-warehouse",
111
- "favorite_food": "carrots"
112
- },
113
- {
114
- "character_name": "Saundra Kauble",
115
- "species": "dog",
116
- "catchphrase": "Synchronised 24/7 support",
117
- "favorite_food": "carrots"
118
- },
119
- {
120
- "character_name": "Kain Viggars",
121
- "species": "cat",
122
- "catchphrase": "Open-architected asymmetric circuit",
123
- "favorite_food": "carrots"
124
- }
125
- ]
126
- JSON
127
- end
128
-
129
- before do
130
- file.write(json)
131
- file.rewind
132
- end
133
-
134
- after do
135
- file.close
136
- file.unlink
137
- end
138
-
139
- it 'Ingests a JSON file' do
140
- response = bulk_helper.ingest_json(file)
141
-
142
- expect(response).to be_an_instance_of Elasticsearch::API::Response
143
- expect(response.status).to eq(200)
144
- end
145
-
146
- context 'with data not in root of JSON file' do
147
- let(:json) do
148
- json = <<~JSON
149
- {
150
- "field": "value",
151
- "status": 200,
152
- "data": {
153
- "items": [
154
- {
155
- "character_name": "Anallese Lonie",
156
- "species": "mouse",
157
- "catchphrase": "Seamless regional definition",
158
- "favorite_food": "pizza"
159
- },
160
- {
161
- "character_name": "Janey Davidovsky",
162
- "species": "cat",
163
- "catchphrase": "Down-sized responsive pricing structure",
164
- "favorite_food": "pizza"
165
- },
166
- {
167
- "character_name": "Morse Mountford",
168
- "species": "cat",
169
- "catchphrase": "Ameliorated modular data-warehouse",
170
- "favorite_food": "carrots"
171
- },
172
- {
173
- "character_name": "Saundra Kauble",
174
- "species": "dog",
175
- "catchphrase": "Synchronised 24/7 support",
176
- "favorite_food": "carrots"
177
- },
178
- {
179
- "character_name": "Kain Viggars",
180
- "species": "cat",
181
- "catchphrase": "Open-architected asymmetric circuit",
182
- "favorite_food": "carrots"
183
- }
184
- ]
185
- }
186
- }
187
- JSON
188
- end
189
-
190
- it 'Ingests a JSON file passing keys as Array' do
191
- response = bulk_helper.ingest_json(file, { keys: ['data', 'items'] })
192
- expect(response).to be_an_instance_of Elasticsearch::API::Response
193
- expect(response.status).to eq(200)
194
- expect(response['items'].map { |a| a['index']['status'] }.uniq.first).to eq 201
195
- end
196
-
197
- it 'Ingests a JSON file passing keys as String' do
198
- response = bulk_helper.ingest_json(file, { keys: 'data,items' })
199
- expect(response).to be_an_instance_of Elasticsearch::API::Response
200
- expect(response.status).to eq(200)
201
- expect(response['items'].map { |a| a['index']['status'] }.uniq.first).to eq 201
202
- end
203
- end
204
- end
205
- end
206
- end