elasticsearch 8.0.0.pre1 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca479af01bac2b0dd8b654294c63f0f1bc675cd69036f9704ae9fd1b22684546
4
- data.tar.gz: c2252be5532689f299dfb3084215beab37a797358d41cc355e74fa820c63cf42
3
+ metadata.gz: b4a75131520baa75c7b646578951dcd420fc640628ee0897a2b60a9f65ce8290
4
+ data.tar.gz: e0d8973646685dbf3575011e1ebbbd3e5dc599b37242306ef8bdf2a2a12ba5df
5
5
  SHA512:
6
- metadata.gz: 27abb64b012188c2dd762c4e1a856dd84a80624a7d2c478b55ed84ab7cde54952c507847ac52a13c5c9170c9bfce5114ca4174c0ac5ae0d05fe234bd7a8a8f8a
7
- data.tar.gz: 1f4a3e1ef357eba8709fe91a24c0d677835b40586232427c62372c0ce2a45b707cce51c02618235cdaf44567a408ab30c7da5e4172ef6010cdb6a20f9b57fdf1
6
+ metadata.gz: 7bf711aaed6971e4438f846fe34594cbf6d58921742bd4f49914f27f31453fe451a82e09da4b691468156ec25b6039aaa0bf9ae1c87d38808979b0cd2e9aed53
7
+ data.tar.gz: 5188206505493fa7e820e7fdfe2cbbe375fd3efd1957db36d2d9b8d01c4d084f0fb7e482edb9429f9eda92969b9beac534901801f03a38764d61ee161e6058c7
@@ -1,27 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  $LOAD_PATH.unshift(File.expand_path('../../elasticsearch/lib', __dir__))
4
- $LOAD_PATH.unshift(File.expand_path('../../elasticsearch-dsl/lib', __dir__))
5
4
  $LOAD_PATH.unshift(File.expand_path('../../elasticsearch-api/lib', __dir__))
6
5
 
7
6
  require 'elasticsearch'
8
7
  require 'elasticsearch-api'
9
- require 'elasticsearch-dsl'
10
-
11
- gems_not_loaded = ['elasticsearch-dsl'].reject do |gem|
12
- begin
13
- (require gem) || true
14
- rescue LoadError
15
- false
16
- end
17
- end
18
-
19
- unless gems_not_loaded.empty?
20
- warn "The following gems were not loaded: [#{gems_not_loaded.join(', ')}]. Please install and require them explicitly."
21
- end
22
8
 
23
9
  include Elasticsearch
24
- include Elasticsearch::DSL if defined?(Elasticsearch::DSL)
25
10
 
26
11
  begin
27
12
  require 'pry'
@@ -45,8 +45,8 @@ Gem::Specification.new do |s|
45
45
 
46
46
  s.required_ruby_version = '>= 2.5'
47
47
 
48
- s.add_dependency 'elastic-transport', '8.0.0.pre2'
49
- s.add_dependency 'elasticsearch-api', '8.0.0.pre1'
48
+ s.add_dependency 'elastic-transport', '8.0.0'
49
+ s.add_dependency 'elasticsearch-api', '8.0.0'
50
50
 
51
51
  s.add_development_dependency 'bundler'
52
52
  s.add_development_dependency 'byebug' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
@@ -16,5 +16,5 @@
16
16
  # under the License.
17
17
 
18
18
  module Elasticsearch
19
- VERSION = '8.0.0.pre1'.freeze
19
+ VERSION = '8.0.0'.freeze
20
20
  end
data/lib/elasticsearch.rb CHANGED
@@ -22,6 +22,7 @@ require 'elasticsearch/api'
22
22
  module Elasticsearch
23
23
  NOT_ELASTICSEARCH_WARNING = 'The client noticed that the server is not Elasticsearch and we do not support this unknown product.'.freeze
24
24
  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
25
+ VALIDATION_WARNING = 'The client is unable to verify that the server is Elasticsearch. Some functionality may not be compatible if the server is running an unsupported product.'.freeze
25
26
 
26
27
  # This is the stateful Elasticsearch::Client, using an instance of elastic-transport.
27
28
  class Client
@@ -66,10 +67,8 @@ module Elasticsearch
66
67
  opaque_id = @opaque_id_prefix ? "#{@opaque_id_prefix}#{opaque_id}" : opaque_id
67
68
  args[4] = headers.merge('X-Opaque-Id' => opaque_id)
68
69
  end
69
- if name == :perform_request
70
- verify_elasticsearch unless @verified
71
- @transport.perform_request(*args, &block)
72
- end
70
+ verify_elasticsearch unless @verified
71
+ @transport.perform_request(*args, &block)
73
72
  else
74
73
  @transport.send(name, *args, &block)
75
74
  end
@@ -85,20 +84,27 @@ module Elasticsearch
85
84
  begin
86
85
  response = elasticsearch_validation_request
87
86
  rescue Elastic::Transport::Transport::Errors::Unauthorized,
88
- Elastic::Transport::Transport::Errors::Forbidden
87
+ Elastic::Transport::Transport::Errors::Forbidden,
88
+ Elastic::Transport::Transport::Errors::RequestEntityTooLarge
89
89
  @verified = true
90
90
  warn(SECURITY_PRIVILEGES_VALIDATION_WARNING)
91
91
  return
92
+ rescue Elastic::Transport::Transport::Error
93
+ warn(VALIDATION_WARNING)
94
+ return
92
95
  end
93
96
 
94
97
  body = if response.headers['content-type'] == 'application/yaml'
95
98
  require 'yaml'
96
- YAML.load(response.body)
99
+ YAML.safe_load(response.body)
97
100
  else
98
101
  response.body
99
102
  end
100
103
  version = body.dig('version', 'number')
101
104
  verify_with_version_or_header(version, response.headers)
105
+ rescue StandardError => e
106
+ warn(VALIDATION_WARNING)
107
+ raise e
102
108
  end
103
109
 
104
110
  def verify_with_version_or_header(version, headers)
@@ -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
+ 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
+
22
+ context 'Elasticsearch client' do
23
+ let(:client) do
24
+ Elasticsearch::Client.new(host: ELASTICSEARCH_URL, user: 'elastic', password: 'changeme')
25
+ end
26
+ let(:index) { 'tvs' }
27
+
28
+ after do
29
+ client.indices.delete(index: index)
30
+ end
31
+
32
+ context 'escaping spaces in ids' do
33
+ it 'escapes spaces for id when using index' do
34
+ response = client.index(index: index, id: 'a test 1', body: { name: 'A test 1' }, refresh: true)
35
+ expect(response.body['_id']).to eq 'a test 1'
36
+
37
+ response = client.search(index: index)
38
+ expect(response.body['hits']['hits'].first['_id']).to eq 'a test 1'
39
+
40
+ # Raises exception, _id is unrecognized
41
+ expect do
42
+ client.index(index: index, _id: 'a test 2', body: { name: 'A test 2' })
43
+ end.to raise_exception Elastic::Transport::Transport::Errors::BadRequest
44
+
45
+ # Raises exception, id is a query parameter
46
+ expect do
47
+ client.index(index: index, body: { name: 'A test 3', _id: 'a test 3' })
48
+ end.to raise_exception Elastic::Transport::Transport::Errors::BadRequest
49
+ end
50
+
51
+ it 'escapes spaces for id when using create' do
52
+ # Works with create
53
+ response = client.create(index: index, id: 'a test 4', body: { name: 'A test 4' })
54
+ expect(response.body['_id']).to eq 'a test 4'
55
+ end
56
+
57
+ it 'escapes spaces for id when using bulk' do
58
+ body = [
59
+ { create: { _index: index, _id: 'a test 5', data: { name: 'A test 5' } } }
60
+ ]
61
+ expect(client.bulk(body: body, refresh: true).status).to eq 200
62
+
63
+ response = client.search(index: index)
64
+ expect(
65
+ response.body['hits']['hits'].select { |a| a['_id'] == 'a test 5' }.size
66
+ ).to eq 1
67
+ end
68
+ end
69
+
70
+ context 'it doesnae escape plus signs in id' do
71
+ it 'escapes spaces for id when using index' do
72
+ response = client.index(index: index, id: 'a+test+1', body: { name: 'A test 1' })
73
+ expect(response.body['_id']).to eq 'a+test+1'
74
+ end
75
+
76
+ it 'escapes spaces for id when using create' do
77
+ # Works with create
78
+ response = client.create(index: index, id: 'a+test+2', body: { name: 'A test 2' })
79
+ expect(response.body['_id']).to eq 'a+test+2'
80
+ end
81
+
82
+ it 'escapes spaces for id when using bulk' do
83
+ body = [
84
+ { create: { _index: index, _id: 'a+test+3', data: { name: 'A test 3' } } }
85
+ ]
86
+ expect(client.bulk(body: body, refresh: true).status).to eq 200
87
+
88
+ response = client.search(index: index)
89
+ expect(
90
+ response.body['hits']['hits'].select { |a| a['_id'] == 'a+test+3' }.size
91
+ ).to eq 1
92
+ end
93
+ end
94
+ end
@@ -25,7 +25,7 @@ describe 'Elasticsearch: Validation' do
25
25
  .to_return(status: status, body: body, headers: headers)
26
26
  end
27
27
  let(:count_request_stub) do
28
- stub_request(:post, "#{host}/_count")
28
+ stub_request(:get, "#{host}/_count")
29
29
  .to_return(status: 200, body: nil, headers: {})
30
30
  end
31
31
  let(:status) { 200 }
@@ -51,7 +51,7 @@ describe 'Elasticsearch: Validation' do
51
51
  client.count
52
52
  expect(client.instance_variable_get('@verified'))
53
53
  assert_requested :get, host
54
- assert_requested :post, "#{host}/_count"
54
+ assert_requested :get, "#{host}/_count"
55
55
  end
56
56
 
57
57
  context 'When Elasticsearch replies with status 401' do
@@ -65,7 +65,6 @@ describe 'Elasticsearch: Validation' do
65
65
 
66
66
  verify_request_stub
67
67
  count_request_stub
68
-
69
68
  valid_requests_and_expectations
70
69
 
71
70
  fake_stderr.rewind
@@ -86,7 +85,6 @@ describe 'Elasticsearch: Validation' do
86
85
 
87
86
  verify_request_stub
88
87
  count_request_stub
89
-
90
88
  valid_requests_and_expectations
91
89
 
92
90
  fake_stderr.rewind
@@ -96,6 +94,60 @@ describe 'Elasticsearch: Validation' do
96
94
  end
97
95
  end
98
96
 
97
+ context 'When Elasticsearch replies with status 413' do
98
+ let(:status) { 413 }
99
+ let(:body) { {}.to_json }
100
+
101
+ it 'Verifies the request and shows a warning' do
102
+ stderr = $stderr
103
+ fake_stderr = StringIO.new
104
+ $stderr = fake_stderr
105
+
106
+ expect(client.instance_variable_get('@verified')).to be false
107
+ assert_not_requested :get, host
108
+ verify_request_stub
109
+ expect { client.info }.to raise_error Elastic::Transport::Transport::Errors::RequestEntityTooLarge
110
+ expect(client.instance_variable_get('@verified')).to be true
111
+
112
+ fake_stderr.rewind
113
+ expect(fake_stderr.string.delete("\n"))
114
+ .to eq(Elasticsearch::SECURITY_PRIVILEGES_VALIDATION_WARNING)
115
+ ensure
116
+ $stderr = stderr
117
+ end
118
+ end
119
+
120
+ context 'When Elasticsearch replies with status 503' do
121
+ let(:status) { 503 }
122
+ let(:body) { {}.to_json }
123
+
124
+ it 'Does not verify the request and shows a warning' do
125
+ stderr = $stderr
126
+ fake_stderr = StringIO.new
127
+ $stderr = fake_stderr
128
+
129
+ expect(client.instance_variable_get('@verified')).to be false
130
+ assert_not_requested :get, host
131
+ verify_request_stub
132
+ expect { client.info }.to raise_error Elastic::Transport::Transport::Errors::ServiceUnavailable
133
+ assert_not_requested :post, "#{host}/_count"
134
+ expect(client.instance_variable_get('@verified')).to be false
135
+
136
+ fake_stderr.rewind
137
+ expect(fake_stderr.string)
138
+ .to eq(
139
+ <<~MSG
140
+ The client is unable to verify that the server is \
141
+ Elasticsearch. Some functionality may not be compatible \
142
+ if the server is running an unsupported product.
143
+ MSG
144
+ )
145
+ ensure
146
+ $stderr = stderr
147
+ end
148
+ end
149
+
150
+
99
151
  context 'When the Elasticsearch version is >= 8.0.0' do
100
152
  context 'With a valid Elasticsearch response' do
101
153
  let(:body) { { 'version' => { 'number' => '8.0.0' } }.to_json }
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.0.0.pre1
4
+ version: 8.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karel Minarik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-04 00:00:00.000000000 Z
11
+ date: 2022-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: elastic-transport
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 8.0.0.pre2
19
+ version: 8.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 8.0.0.pre2
26
+ version: 8.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: elasticsearch-api
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 8.0.0.pre1
33
+ version: 8.0.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.0.0.pre1
40
+ version: 8.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -200,6 +200,7 @@ files:
200
200
  - lib/elasticsearch-ruby.rb
201
201
  - lib/elasticsearch.rb
202
202
  - lib/elasticsearch/version.rb
203
+ - spec/integration/characters_escaping_spec.rb
203
204
  - spec/integration/client_integration_spec.rb
204
205
  - spec/spec_helper.rb
205
206
  - spec/unit/api_key_spec.rb
@@ -229,15 +230,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
229
230
  version: '2.5'
230
231
  required_rubygems_version: !ruby/object:Gem::Requirement
231
232
  requirements:
232
- - - ">"
233
+ - - ">="
233
234
  - !ruby/object:Gem::Version
234
- version: 1.3.1
235
+ version: '0'
235
236
  requirements: []
236
- rubygems_version: 3.2.22
237
+ rubygems_version: 3.3.3
237
238
  signing_key:
238
239
  specification_version: 4
239
240
  summary: Ruby integrations for Elasticsearch
240
241
  test_files:
242
+ - spec/integration/characters_escaping_spec.rb
241
243
  - spec/integration/client_integration_spec.rb
242
244
  - spec/spec_helper.rb
243
245
  - spec/unit/api_key_spec.rb