elasticsearch 7.13.3 → 7.17.11

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: 1dd904fe3389952a5434f9bdd54e43b085d686146620423f1f55e5e1cfcea9cc
4
- data.tar.gz: 8456c08f65bde635e6238f01f6227d4688003c1083ac69c6b45029ba031d7679
3
+ metadata.gz: b7dea8ec1e6bc10290c106750742be40c553819c725a33a54f67f4b3c92578ec
4
+ data.tar.gz: f8173933ab9db901e172c208b4ea769fafa7cd98475eb7035d2b3542862a57e3
5
5
  SHA512:
6
- metadata.gz: cc9635e7f85dddfec58ea02f18f31a586f0e671abbbfb19038564c976097d982bad0f1777b94798a1f4baca88213d7ac03ca27dc162792903eed1724f3f62289
7
- data.tar.gz: c4aeeeb547a5e678ff1421b0fbcdc521662d6606afc359f6e813cf38278b274be320e2b912d09b7e722f2a46f8518fbe0a741748f2f9ff10c8a407b703e11d2b
6
+ metadata.gz: 225446c957d3fee823ea16717957254e5cf192bc088312a75d8b8455805d8b8bf5f6190f2751041f37d35a635f806d3431c042564945cba5f152efdb41cc2491
7
+ data.tar.gz: 11823bccb69fc6703605f9d3b75bb9f5c8c0b1c3a2074f36b7d175a6e56d29acbd1adc142f99a9186f5b95e94156c19ca9eb5df107a9b5662ec592bc3a42e621
data/README.md CHANGED
@@ -86,6 +86,10 @@ Please refer to the specific library documentation for details:
86
86
  [[README]](https://github.com/elasticsearch/elasticsearch-ruby/blob/master/elasticsearch-api/README.md)
87
87
  [[Documentation]](http://rubydoc.info/gems/elasticsearch-api/file/README.markdown)
88
88
 
89
+ ## Development
90
+
91
+ You can run `rake -T` to check the test tasks. Use `COVERAGE=true` before running a test task to check the coverage with Simplecov.
92
+
89
93
  ## License
90
94
 
91
95
  This software is licensed under the [Apache 2 license](./LICENSE).
data/Rakefile CHANGED
@@ -15,40 +15,35 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- require "bundler/gem_tasks"
18
+ require 'bundler/gem_tasks'
19
19
 
20
- desc "Run unit tests"
21
- task :test => 'test:unit'
20
+ task(:default) { system 'rake --tasks' }
21
+
22
+ desc 'Run unit tests'
23
+ task test: 'test:spec'
22
24
 
23
25
  # ----- Test tasks ------------------------------------------------------------
26
+ require 'rspec/core/rake_task'
24
27
 
25
- require 'rake/testtask'
26
28
  namespace :test do
27
- desc "Wait for Elasticsearch to be in a green state"
29
+ desc 'Wait for Elasticsearch to be in a green state'
28
30
  task :wait_for_green do
29
31
  sh '../scripts/wait-cluster.sh'
30
32
  end
31
33
 
32
- Rake::TestTask.new(:unit) do |test|
33
- test.libs << 'lib' << 'test'
34
- test.test_files = FileList["test/unit/**/*_test.rb"]
35
- test.verbose = false
36
- test.warning = false
34
+ RSpec::Core::RakeTask.new(:integration) do |t|
35
+ t.pattern = 'spec/integration/**{,/*/**}/*_spec.rb'
37
36
  end
38
37
 
39
- Rake::TestTask.new(:integration) do |test|
40
- test.deps = [ :wait_for_green ]
41
- test.libs << 'lib' << 'test'
42
- test.test_files = FileList["test/integration/**/*_test.rb"]
43
- test.verbose = false
44
- test.warning = false
38
+ RSpec::Core::RakeTask.new(:unit) do |t|
39
+ t.pattern = 'spec/unit/**{,/*/**}/*_spec.rb'
45
40
  end
46
41
 
47
- Rake::TestTask.new(:all) do |test|
48
- test.libs << 'lib' << 'test'
49
- test.test_files = FileList["test/unit/**/*_test.rb", "test/integration/**/*_test.rb"]
42
+ desc 'Run unit and integration tests'
43
+ task :all do
44
+ Rake::Task['test:unit'].invoke
45
+ Rake::Task['test:integration'].invoke
50
46
  end
51
-
52
47
  end
53
48
 
54
49
  # ----- Documentation tasks ---------------------------------------------------
@@ -25,12 +25,12 @@ Gem::Specification.new do |s|
25
25
  s.authors = ['Karel Minarik']
26
26
  s.email = ['karel.minarik@elasticsearch.org']
27
27
  s.summary = 'Ruby integrations for Elasticsearch'
28
- s.homepage = 'https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/7.x/index.html'
28
+ s.homepage = 'https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/7.16/index.html'
29
29
  s.license = 'Apache-2.0'
30
30
  s.metadata = {
31
- 'homepage_uri' => 'https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/7.x/index.html',
32
- 'changelog_uri' => 'https://github.com/elastic/elasticsearch-ruby/blob/7.x/CHANGELOG.md',
33
- 'source_code_uri' => 'https://github.com/elastic/elasticsearch-ruby/tree/7.x',
31
+ 'homepage_uri' => 'https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/7.16/index.html',
32
+ 'changelog_uri' => 'https://github.com/elastic/elasticsearch-ruby/blob/7.16/CHANGELOG.md',
33
+ 'source_code_uri' => 'https://github.com/elastic/elasticsearch-ruby/tree/7.16',
34
34
  'bug_tracker_uri' => 'https://github.com/elastic/elasticsearch-ruby/issues'
35
35
  }
36
36
  s.files = `git ls-files`.split($/)
@@ -45,31 +45,19 @@ Gem::Specification.new do |s|
45
45
 
46
46
  s.required_ruby_version = '>= 2.4'
47
47
 
48
- s.add_dependency 'elasticsearch-transport', '7.13.3'
49
- s.add_dependency 'elasticsearch-api', '7.13.3'
48
+ s.add_dependency 'elasticsearch-transport', '7.17.11'
49
+ s.add_dependency 'elasticsearch-api', '7.17.11'
50
50
 
51
51
  s.add_development_dependency 'bundler'
52
-
53
- s.add_development_dependency 'rake', '~> 13'
54
-
55
- s.add_development_dependency 'elasticsearch-extensions'
56
-
57
- s.add_development_dependency 'ansi'
58
- s.add_development_dependency 'shoulda-context'
59
- s.add_development_dependency 'mocha'
60
- s.add_development_dependency 'yard'
52
+ s.add_development_dependency 'byebug' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
61
53
  s.add_development_dependency 'pry'
62
-
63
-
64
- s.add_development_dependency 'minitest'
65
- s.add_development_dependency 'minitest-reporters'
66
- s.add_development_dependency 'ruby-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
54
+ s.add_development_dependency 'rake', '~> 13'
67
55
  s.add_development_dependency 'require-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
68
- s.add_development_dependency 'simplecov', '~> 0.17', '< 0.18'
69
- s.add_development_dependency 'simplecov-rcov'
70
- s.add_development_dependency 'cane'
71
-
72
- s.add_development_dependency 'test-unit', '~> 2'
56
+ s.add_development_dependency 'rspec'
57
+ s.add_development_dependency 'ruby-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
58
+ s.add_development_dependency 'simplecov'
59
+ s.add_development_dependency 'webmock'
60
+ s.add_development_dependency 'yard'
73
61
 
74
62
  s.description = <<-DESC.gsub(/^ /, '')
75
63
  Ruby integrations for Elasticsearch (client, API, etc.)
@@ -16,5 +16,5 @@
16
16
  # under the License.
17
17
 
18
18
  module Elasticsearch
19
- VERSION = '7.13.3'.freeze
19
+ VERSION = '7.17.11'.freeze
20
20
  end
data/lib/elasticsearch.rb CHANGED
@@ -15,18 +15,92 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- require "elasticsearch/version"
19
-
18
+ require 'elasticsearch/version'
20
19
  require 'elasticsearch/transport'
21
20
  require 'elasticsearch/api'
22
21
 
23
22
  module Elasticsearch
24
- module Transport
25
- class Client
26
- include Elasticsearch::API
23
+ SECURITY_PRIVILEGES_VALIDATION_WARNING = 'The client is unable to verify that the server is Elasticsearch due to security privileges on the server side. Some functionality may not be compatible if the server is running an unsupported product.'.freeze
24
+ NOT_ELASTICSEARCH_WARNING = 'The client noticed that the server is not Elasticsearch and we do not support this unknown product.'.freeze
25
+ NOT_SUPPORTED_ELASTICSEARCH_WARNING = 'The client noticed that the server is not a supported distribution of Elasticsearch.'.freeze
26
+ YOU_KNOW_FOR_SEARCH = 'You Know, for Search'.freeze
27
+
28
+ class Client
29
+ include Elasticsearch::API
30
+ attr_accessor :transport
31
+
32
+ # See Elasticsearch::Transport::Client for initializer parameters
33
+ def initialize(arguments = {}, &block)
34
+ @verified = false
35
+ @transport = Elasticsearch::Transport::Client.new(arguments, &block)
36
+ end
37
+
38
+ def method_missing(name, *args, &block)
39
+ if name == :perform_request
40
+ verify_elasticsearch unless @verified
41
+ @transport.perform_request(*args, &block)
42
+ else
43
+ super
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def verify_elasticsearch
50
+ begin
51
+ response = elasticsearch_validation_request
52
+ rescue Elasticsearch::Transport::Transport::Errors::Unauthorized,
53
+ Elasticsearch::Transport::Transport::Errors::Forbidden,
54
+ Elasticsearch::Transport::Transport::Errors::RequestEntityTooLarge
55
+ @verified = true
56
+ warn(SECURITY_PRIVILEGES_VALIDATION_WARNING)
57
+ return
58
+ end
59
+
60
+ body = if response.headers['content-type'] == 'application/yaml'
61
+ require 'yaml'
62
+ YAML.safe_load(response.body)
63
+ else
64
+ response.body
65
+ end
66
+ version = body.dig('version', 'number')
67
+ verify_with_version_or_header(body, version, response.headers)
68
+ end
69
+
70
+ def verify_with_version_or_header(body, version, headers)
71
+ raise Elasticsearch::UnsupportedProductError if version.nil? || version < '6.0.0'
72
+
73
+ if version == '7.x-SNAPSHOT' || Gem::Version.new(version) >= Gem::Version.new('7.14-SNAPSHOT')
74
+ raise Elasticsearch::UnsupportedProductError unless headers['x-elastic-product'] == 'Elasticsearch'
75
+
76
+ @verified = true
77
+ elsif Gem::Version.new(version) > Gem::Version.new('6.0.0') &&
78
+ Gem::Version.new(version) < Gem::Version.new('7.0.0')
79
+ raise Elasticsearch::UnsupportedProductError unless
80
+ body['tagline'] == YOU_KNOW_FOR_SEARCH
81
+
82
+ @verified = true
83
+ elsif Gem::Version.new(version) >= Gem::Version.new('7.0.0') &&
84
+ Gem::Version.new(version) < Gem::Version.new('7.14-SNAPSHOT')
85
+ raise Elasticsearch::UnsupportedProductError unless body['tagline'] == YOU_KNOW_FOR_SEARCH
86
+ raise Elasticsearch::UnsupportedProductError.new(NOT_SUPPORTED_ELASTICSEARCH_WARNING) unless body.dig('version', 'build_flavor') == 'default'
87
+
88
+ @verified = true
89
+ end
90
+ end
91
+
92
+ def elasticsearch_validation_request
93
+ @transport.perform_request('GET', '/')
94
+ end
95
+ end
96
+
97
+ class UnsupportedProductError < StandardError
98
+ def initialize(message = NOT_ELASTICSEARCH_WARNING)
99
+ super(message)
27
100
  end
28
101
  end
29
102
  end
103
+
30
104
  module Elastic
31
105
  # If the version is X.X.X.pre/alpha/beta, use X.X.Xp for the meta-header:
32
106
  def self.client_meta_version
@@ -0,0 +1,97 @@
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 'uri'
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
+ require 'spec_helper'
24
+
25
+ context 'Elasticsearch client' do
26
+ let(:client) do
27
+ Elasticsearch::Client.new(host: ELASTICSEARCH_URL, user: 'elastic', password: 'changeme')
28
+ end
29
+ let(:index) { 'tvs' }
30
+
31
+ after do
32
+ client.indices.delete(index: index)
33
+ end
34
+
35
+ context 'escaping spaces in ids' do
36
+ it 'escapes spaces for id when using index' do
37
+ response = client.index(index: index, id: 'a test 1', body: { name: 'A test 1' }, refresh: true)
38
+ expect(response['_id']).to eq 'a test 1'
39
+
40
+ response = client.search(index: index)
41
+ expect(response['hits']['hits'].first['_id']).to eq 'a test 1'
42
+
43
+ # Raises exception, _id is unrecognized
44
+ expect do
45
+ client.index(index: index, _id: 'a test 2', body: { name: 'A test 2' })
46
+ end.to raise_exception ArgumentError
47
+
48
+ # Raises exception, id is a query parameter
49
+ expect do
50
+ client.index(index: index, body: { name: 'A test 3', _id: 'a test 3' })
51
+ end.to raise_exception Elasticsearch::Transport::Transport::Errors::BadRequest
52
+ end
53
+
54
+ it 'escapes spaces for id when using create' do
55
+ # Works with create
56
+ response = client.create(index: index, id: 'a test 4', body: { name: 'A test 4' })
57
+ expect(response['_id']).to eq 'a test 4'
58
+ end
59
+
60
+ it 'escapes spaces for id when using bulk' do
61
+ body = [
62
+ { create: { _index: index, _id: 'a test 5', data: { name: 'A test 5' } } }
63
+ ]
64
+ expect(client.bulk(body: body, refresh: true))
65
+
66
+ response = client.search(index: index)
67
+ expect(
68
+ response['hits']['hits'].select { |a| a['_id'] == 'a test 5' }.size
69
+ ).to eq 1
70
+ end
71
+ end
72
+
73
+ context 'it doesnae escape plus signs in id' do
74
+ it 'escapes spaces for id when using index' do
75
+ response = client.index(index: index, id: 'a+test+1', body: { name: 'A test 1' })
76
+ expect(response['_id']).to eq 'a+test+1'
77
+ end
78
+
79
+ it 'escapes spaces for id when using create' do
80
+ # Works with create
81
+ response = client.create(index: index, id: 'a+test+2', body: { name: 'A test 2' })
82
+ expect(response['_id']).to eq 'a+test+2'
83
+ end
84
+
85
+ it 'escapes spaces for id when using bulk' do
86
+ body = [
87
+ { create: { _index: index, _id: 'a+test+3', data: { name: 'A test 3' } } }
88
+ ]
89
+ expect(client.bulk(body: body, refresh: true))
90
+
91
+ response = client.search(index: index)
92
+ expect(
93
+ response['hits']['hits'].select { |a| a['_id'] == 'a+test+3' }.size
94
+ ).to eq 1
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,57 @@
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 'spec_helper'
18
+ require 'logger'
19
+
20
+ context 'Elasticsearch client' do
21
+ let(:logger) { Logger.new($stderr) }
22
+
23
+ let(:client) do
24
+ Elasticsearch::Client.new(
25
+ host: ELASTICSEARCH_URL,
26
+ logger: logger
27
+ )
28
+ end
29
+
30
+ context 'Integrates with elasticsearch API' do
31
+ it 'should perform the API methods' do
32
+ expect do
33
+ # Index a document
34
+ client.index(index: 'test-index', id: '1', body: { title: 'Test' })
35
+
36
+ # Refresh the index
37
+ client.indices.refresh(index: 'test-index')
38
+
39
+ # Search
40
+ response = client.search(index: 'test-index', body: { query: { match: { title: 'test' } } })
41
+
42
+ expect(response['hits']['total']['value']).to eq 1
43
+ expect(response['hits']['hits'][0]['_source']['title']).to eq 'Test'
44
+
45
+ # Delete the index
46
+ client.indices.delete(index: 'test-index')
47
+ end.not_to raise_error
48
+ end
49
+ end
50
+
51
+ context 'Reports the right meta header' do
52
+ it 'Reports es service name and gem version' do
53
+ headers = client.transport.transport.connections.first.connection.headers
54
+ expect(headers['x-elastic-client-meta']).to match Elastic.client_meta_version
55
+ end
56
+ end
57
+ end
@@ -14,30 +14,17 @@
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
-
18
- require 'test_helper'
19
-
20
- module Elasticsearch
21
- module Test
22
- class WrapperGemTest < Minitest::Test
23
-
24
- context "Wrapper gem" do
25
-
26
- should "require all neccessary subgems" do
27
- assert defined? Elasticsearch::Client
28
- assert defined? Elasticsearch::API
29
- end
30
-
31
- should "mix the API into the client" do
32
- client = Elasticsearch::Client.new
33
-
34
- assert_respond_to client, :search
35
- assert_respond_to client, :cluster
36
- assert_respond_to client, :indices
37
- end
38
-
39
- end
40
-
41
- end
17
+ require 'spec_helper'
18
+ require 'logger'
19
+
20
+ describe 'Elasticsearch validation integration' do
21
+ it 'Validates for Elasticsearch > 7.14' do
22
+ client = Elasticsearch::Client.new(
23
+ host: ELASTICSEARCH_URL,
24
+ logger: Logger.new($stderr)
25
+ )
26
+ expect(client.instance_variable_get('@verified')).to be false
27
+ client.count
28
+ expect(client.instance_variable_get('@verified')).to be true
42
29
  end
43
30
  end
@@ -0,0 +1,26 @@
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 'elasticsearch'
19
+ require 'rspec'
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
+ RSpec.configure do |config|
25
+ config.formatter = :documentation
26
+ end