elasticsearch 7.17.11 → 9.0.2
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 +4 -4
- data/README.md +71 -37
- data/bin/elastic_ruby_console +2 -18
- data/elasticsearch.gemspec +21 -19
- data/lib/elasticsearch/helpers/bulk_helper.rb +129 -0
- data/lib/elasticsearch/helpers/esql_helper.rb +72 -0
- data/lib/elasticsearch/helpers/scroll_helper.rb +85 -0
- data/lib/elasticsearch/version.rb +1 -1
- data/lib/elasticsearch.rb +150 -44
- metadata +43 -43
- data/Gemfile +0 -33
- data/Rakefile +0 -54
- data/spec/integration/characters_escaping_spec.rb +0 -97
- data/spec/integration/client_integration_spec.rb +0 -57
- data/spec/integration/validation_integration_spec.rb +0 -30
- data/spec/spec_helper.rb +0 -26
- data/spec/unit/elasticsearch_product_validation_spec.rb +0 -466
- data/spec/unit/wrapper_gem_spec.rb +0 -39
- /data/{LICENSE → LICENSE.txt} +0 -0
data/lib/elasticsearch.rb
CHANGED
|
@@ -16,84 +16,189 @@
|
|
|
16
16
|
# under the License.
|
|
17
17
|
|
|
18
18
|
require 'elasticsearch/version'
|
|
19
|
-
require '
|
|
19
|
+
require 'elastic/transport'
|
|
20
20
|
require 'elasticsearch/api'
|
|
21
21
|
|
|
22
22
|
module Elasticsearch
|
|
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
23
|
NOT_ELASTICSEARCH_WARNING = 'The client noticed that the server is not Elasticsearch and we do not support this unknown product.'.freeze
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
27
26
|
|
|
27
|
+
# This is the stateful Elasticsearch::Client, using an instance of elastic-transport.
|
|
28
28
|
class Client
|
|
29
29
|
include Elasticsearch::API
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
#
|
|
30
|
+
# The default port to use if connecting using a Cloud ID.
|
|
31
|
+
# Updated from 9243 to 443 in client version 7.10.1
|
|
32
|
+
#
|
|
33
|
+
# @since 7.2.0
|
|
34
|
+
DEFAULT_CLOUD_PORT = 443
|
|
35
|
+
|
|
36
|
+
# Create a client connected to an Elasticsearch cluster.
|
|
37
|
+
#
|
|
38
|
+
# @param [Hash] arguments - initializer arguments
|
|
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
|
|
41
|
+
# `api_key` joined by a colon as a String, or a hash with the `id` and
|
|
42
|
+
# `api_key` values.
|
|
43
|
+
# @option arguments [String] :opaque_id_prefix set a prefix for X-Opaque-Id when initializing the client.
|
|
44
|
+
# This will be prepended to the id you set before each request
|
|
45
|
+
# if you're using X-Opaque-Id
|
|
46
|
+
# @option arguments [Hash] :headers Custom HTTP Request Headers
|
|
47
|
+
#
|
|
33
48
|
def initialize(arguments = {}, &block)
|
|
34
49
|
@verified = false
|
|
35
|
-
@
|
|
50
|
+
@warned = false
|
|
51
|
+
@opaque_id_prefix = arguments[:opaque_id_prefix] || nil
|
|
52
|
+
api_key(arguments) if arguments[:api_key]
|
|
53
|
+
setup_cloud(arguments) if arguments[:cloud_id]
|
|
54
|
+
set_user_agent!(arguments) unless sent_user_agent?(arguments)
|
|
55
|
+
set_content_type!(arguments)
|
|
56
|
+
@transport = Elastic::Transport::Client.new(arguments, &block)
|
|
36
57
|
end
|
|
37
58
|
|
|
38
59
|
def method_missing(name, *args, &block)
|
|
39
|
-
if name
|
|
40
|
-
verify_elasticsearch unless @verified
|
|
41
|
-
@transport.perform_request(*args, &block)
|
|
42
|
-
else
|
|
60
|
+
if methods.include?(name)
|
|
43
61
|
super
|
|
62
|
+
elsif name == :perform_request
|
|
63
|
+
# The signature for perform_request is:
|
|
64
|
+
# method, path, params, body, headers, opts
|
|
65
|
+
if (opaque_id = args[2]&.delete(:opaque_id))
|
|
66
|
+
headers = args[4] || {}
|
|
67
|
+
opaque_id = @opaque_id_prefix ? "#{@opaque_id_prefix}#{opaque_id}" : opaque_id
|
|
68
|
+
args[4] = headers.merge('X-Opaque-Id' => opaque_id)
|
|
69
|
+
end
|
|
70
|
+
if @verified
|
|
71
|
+
@transport.perform_request(*args, &block)
|
|
72
|
+
else
|
|
73
|
+
verify_elasticsearch(*args, &block)
|
|
74
|
+
end
|
|
75
|
+
else
|
|
76
|
+
@transport.send(name, *args, &block)
|
|
44
77
|
end
|
|
45
78
|
end
|
|
46
79
|
|
|
80
|
+
def respond_to_missing?(method_name, *args)
|
|
81
|
+
@transport.respond_to?(method_name) || super
|
|
82
|
+
end
|
|
83
|
+
|
|
47
84
|
private
|
|
48
85
|
|
|
49
|
-
def verify_elasticsearch
|
|
86
|
+
def verify_elasticsearch(*args, &block)
|
|
50
87
|
begin
|
|
51
|
-
response =
|
|
52
|
-
rescue
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
@verified = true
|
|
88
|
+
response = @transport.perform_request(*args, &block)
|
|
89
|
+
rescue Elastic::Transport::Transport::Errors::Unauthorized,
|
|
90
|
+
Elastic::Transport::Transport::Errors::Forbidden,
|
|
91
|
+
Elastic::Transport::Transport::Errors::RequestEntityTooLarge => e
|
|
56
92
|
warn(SECURITY_PRIVILEGES_VALIDATION_WARNING)
|
|
57
|
-
|
|
93
|
+
@verified = true
|
|
94
|
+
raise e
|
|
95
|
+
rescue Elastic::Transport::Transport::Error => e
|
|
96
|
+
unless @warned
|
|
97
|
+
warn(VALIDATION_WARNING)
|
|
98
|
+
@warned = true
|
|
99
|
+
end
|
|
100
|
+
raise e
|
|
101
|
+
rescue StandardError => e
|
|
102
|
+
warn(VALIDATION_WARNING)
|
|
103
|
+
raise e
|
|
58
104
|
end
|
|
105
|
+
raise Elasticsearch::UnsupportedProductError unless response.headers['x-elastic-product'] == 'Elasticsearch'
|
|
59
106
|
|
|
60
|
-
|
|
61
|
-
|
|
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)
|
|
107
|
+
@verified = true
|
|
108
|
+
response
|
|
68
109
|
end
|
|
69
110
|
|
|
70
|
-
def
|
|
71
|
-
|
|
111
|
+
def setup_cloud_host(cloud_id, user, password, port)
|
|
112
|
+
name = cloud_id.split(':')[0]
|
|
113
|
+
base64_decoded = cloud_id.gsub("#{name}:", '').unpack1('m')
|
|
114
|
+
cloud_url, elasticsearch_instance = base64_decoded.split('$')
|
|
72
115
|
|
|
73
|
-
if
|
|
74
|
-
|
|
116
|
+
if cloud_url.include?(':')
|
|
117
|
+
url, port = cloud_url.split(':')
|
|
118
|
+
host = "#{elasticsearch_instance}.#{url}"
|
|
119
|
+
else
|
|
120
|
+
host = "#{elasticsearch_instance}.#{cloud_url}"
|
|
121
|
+
port ||= DEFAULT_CLOUD_PORT
|
|
122
|
+
end
|
|
123
|
+
[{ scheme: 'https', user: user, password: password, host: host, port: port.to_i }]
|
|
124
|
+
end
|
|
75
125
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
126
|
+
def api_key(arguments)
|
|
127
|
+
api_key = if arguments[:api_key].is_a? Hash
|
|
128
|
+
encode(arguments[:api_key])
|
|
129
|
+
else
|
|
130
|
+
arguments[:api_key]
|
|
131
|
+
end
|
|
132
|
+
arguments.delete(:user)
|
|
133
|
+
arguments.delete(:password)
|
|
134
|
+
authorization = { 'Authorization' => "ApiKey #{api_key}" }
|
|
135
|
+
if (headers = arguments.dig(:transport_options, :headers))
|
|
136
|
+
headers.merge!(authorization)
|
|
137
|
+
else
|
|
138
|
+
arguments[:transport_options] ||= {}
|
|
139
|
+
arguments[:transport_options].merge!({ headers: authorization })
|
|
140
|
+
end
|
|
141
|
+
end
|
|
81
142
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
143
|
+
def setup_cloud(arguments)
|
|
144
|
+
arguments[:hosts] = setup_cloud_host(
|
|
145
|
+
arguments[:cloud_id],
|
|
146
|
+
arguments[:user],
|
|
147
|
+
arguments[:password],
|
|
148
|
+
arguments[:port]
|
|
149
|
+
)
|
|
150
|
+
end
|
|
87
151
|
|
|
88
|
-
|
|
89
|
-
|
|
152
|
+
# Encode credentials for the Authorization Header
|
|
153
|
+
# Credentials is the base64 encoding of id and api_key joined by a colon
|
|
154
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html
|
|
155
|
+
def encode(api_key)
|
|
156
|
+
credentials = [api_key[:id], api_key[:api_key]].join(':')
|
|
157
|
+
[credentials].pack('m0')
|
|
90
158
|
end
|
|
91
159
|
|
|
92
160
|
def elasticsearch_validation_request
|
|
93
161
|
@transport.perform_request('GET', '/')
|
|
94
162
|
end
|
|
163
|
+
|
|
164
|
+
def sent_user_agent?(arguments)
|
|
165
|
+
return unless (headers = arguments&.[](:transport_options)&.[](:headers))
|
|
166
|
+
|
|
167
|
+
!!headers.keys.detect { |h| h =~ /user-?_?agent/ }
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def set_user_agent!(arguments)
|
|
171
|
+
user_agent = [
|
|
172
|
+
"elasticsearch-ruby/#{Elasticsearch::VERSION}",
|
|
173
|
+
"elastic-transport-ruby/#{Elastic::Transport::VERSION}",
|
|
174
|
+
"RUBY_VERSION: #{RUBY_VERSION}"
|
|
175
|
+
]
|
|
176
|
+
if RbConfig::CONFIG && RbConfig::CONFIG['host_os']
|
|
177
|
+
user_agent << "#{RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase} #{RbConfig::CONFIG['target_cpu']}"
|
|
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)
|
|
195
|
+
arguments[:transport_options] ||= {}
|
|
196
|
+
arguments[:transport_options][:headers] ||= {}
|
|
197
|
+
arguments[:transport_options][:headers].merge!(header)
|
|
198
|
+
end
|
|
95
199
|
end
|
|
96
200
|
|
|
201
|
+
# Error class for when we detect an unsupported version of Elasticsearch
|
|
97
202
|
class UnsupportedProductError < StandardError
|
|
98
203
|
def initialize(message = NOT_ELASTICSEARCH_WARNING)
|
|
99
204
|
super(message)
|
|
@@ -101,6 +206,7 @@ module Elasticsearch
|
|
|
101
206
|
end
|
|
102
207
|
end
|
|
103
208
|
|
|
209
|
+
# Helper for the meta-header value for Cloud
|
|
104
210
|
module Elastic
|
|
105
211
|
# If the version is X.X.X.pre/alpha/beta, use X.X.Xp for the meta-header:
|
|
106
212
|
def self.client_meta_version
|
|
@@ -111,6 +217,6 @@ module Elastic
|
|
|
111
217
|
Elasticsearch::VERSION
|
|
112
218
|
end
|
|
113
219
|
|
|
114
|
-
# Constant for
|
|
220
|
+
# Constant for elastic-transport meta-header
|
|
115
221
|
ELASTICSEARCH_SERVICE_VERSION = [:es, client_meta_version].freeze
|
|
116
222
|
end
|
metadata
CHANGED
|
@@ -1,43 +1,56 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: elasticsearch
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 9.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
-
|
|
8
|
-
autorequire:
|
|
7
|
+
- Elastic Client Library Maintainers
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 2025-04-24 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: elasticsearch-
|
|
13
|
+
name: elasticsearch-api
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
16
|
- - '='
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
18
|
+
version: 9.0.2
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
23
|
- - '='
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
25
|
+
version: 9.0.2
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
27
|
+
name: elastic-transport
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
30
29
|
requirements:
|
|
31
|
-
- -
|
|
30
|
+
- - "~>"
|
|
32
31
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
32
|
+
version: '8.3'
|
|
34
33
|
type: :runtime
|
|
35
34
|
prerelease: false
|
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
36
|
requirements:
|
|
38
|
-
- -
|
|
37
|
+
- - "~>"
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
39
|
+
version: '8.3'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: base64
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
41
54
|
- !ruby/object:Gem::Dependency
|
|
42
55
|
name: bundler
|
|
43
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -53,7 +66,7 @@ dependencies:
|
|
|
53
66
|
- !ruby/object:Gem::Version
|
|
54
67
|
version: '0'
|
|
55
68
|
- !ruby/object:Gem::Dependency
|
|
56
|
-
name:
|
|
69
|
+
name: debug
|
|
57
70
|
requirement: !ruby/object:Gem::Requirement
|
|
58
71
|
requirements:
|
|
59
72
|
- - ">="
|
|
@@ -84,16 +97,16 @@ dependencies:
|
|
|
84
97
|
name: rake
|
|
85
98
|
requirement: !ruby/object:Gem::Requirement
|
|
86
99
|
requirements:
|
|
87
|
-
- - "
|
|
100
|
+
- - ">="
|
|
88
101
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: '
|
|
102
|
+
version: '0'
|
|
90
103
|
type: :development
|
|
91
104
|
prerelease: false
|
|
92
105
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
106
|
requirements:
|
|
94
|
-
- - "
|
|
107
|
+
- - ">="
|
|
95
108
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: '
|
|
109
|
+
version: '0'
|
|
97
110
|
- !ruby/object:Gem::Dependency
|
|
98
111
|
name: require-prof
|
|
99
112
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -182,39 +195,33 @@ description: 'Ruby integrations for Elasticsearch (client, API, etc.)
|
|
|
182
195
|
|
|
183
196
|
'
|
|
184
197
|
email:
|
|
185
|
-
-
|
|
198
|
+
- client-libs@elastic.co
|
|
186
199
|
executables:
|
|
187
200
|
- elastic_ruby_console
|
|
188
201
|
extensions: []
|
|
189
202
|
extra_rdoc_files:
|
|
190
203
|
- README.md
|
|
191
|
-
- LICENSE
|
|
204
|
+
- LICENSE.txt
|
|
192
205
|
files:
|
|
193
206
|
- ".gitignore"
|
|
194
|
-
-
|
|
195
|
-
- LICENSE
|
|
207
|
+
- LICENSE.txt
|
|
196
208
|
- README.md
|
|
197
|
-
- Rakefile
|
|
198
209
|
- bin/elastic_ruby_console
|
|
199
210
|
- elasticsearch.gemspec
|
|
200
211
|
- lib/elasticsearch-ruby.rb
|
|
201
212
|
- lib/elasticsearch.rb
|
|
213
|
+
- lib/elasticsearch/helpers/bulk_helper.rb
|
|
214
|
+
- lib/elasticsearch/helpers/esql_helper.rb
|
|
215
|
+
- lib/elasticsearch/helpers/scroll_helper.rb
|
|
202
216
|
- lib/elasticsearch/version.rb
|
|
203
|
-
|
|
204
|
-
- spec/integration/client_integration_spec.rb
|
|
205
|
-
- spec/integration/validation_integration_spec.rb
|
|
206
|
-
- spec/spec_helper.rb
|
|
207
|
-
- spec/unit/elasticsearch_product_validation_spec.rb
|
|
208
|
-
- spec/unit/wrapper_gem_spec.rb
|
|
209
|
-
homepage: https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/7.16/index.html
|
|
217
|
+
homepage: https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/index.html
|
|
210
218
|
licenses:
|
|
211
219
|
- Apache-2.0
|
|
212
220
|
metadata:
|
|
213
|
-
homepage_uri: https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/
|
|
214
|
-
changelog_uri: https://github.com/elastic/elasticsearch-ruby/blob/
|
|
215
|
-
source_code_uri: https://github.com/elastic/elasticsearch-ruby/tree/
|
|
221
|
+
homepage_uri: https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/index.html
|
|
222
|
+
changelog_uri: https://github.com/elastic/elasticsearch-ruby/blob/main/CHANGELOG.md
|
|
223
|
+
source_code_uri: https://github.com/elastic/elasticsearch-ruby/tree/main
|
|
216
224
|
bug_tracker_uri: https://github.com/elastic/elasticsearch-ruby/issues
|
|
217
|
-
post_install_message:
|
|
218
225
|
rdoc_options:
|
|
219
226
|
- "--charset=UTF-8"
|
|
220
227
|
require_paths:
|
|
@@ -223,21 +230,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
223
230
|
requirements:
|
|
224
231
|
- - ">="
|
|
225
232
|
- !ruby/object:Gem::Version
|
|
226
|
-
version: '2.
|
|
233
|
+
version: '2.6'
|
|
227
234
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
228
235
|
requirements:
|
|
229
236
|
- - ">="
|
|
230
237
|
- !ruby/object:Gem::Version
|
|
231
238
|
version: '0'
|
|
232
239
|
requirements: []
|
|
233
|
-
rubygems_version: 3.
|
|
234
|
-
signing_key:
|
|
240
|
+
rubygems_version: 3.6.2
|
|
235
241
|
specification_version: 4
|
|
236
242
|
summary: Ruby integrations for Elasticsearch
|
|
237
|
-
test_files:
|
|
238
|
-
- spec/integration/characters_escaping_spec.rb
|
|
239
|
-
- spec/integration/client_integration_spec.rb
|
|
240
|
-
- spec/integration/validation_integration_spec.rb
|
|
241
|
-
- spec/spec_helper.rb
|
|
242
|
-
- spec/unit/elasticsearch_product_validation_spec.rb
|
|
243
|
-
- spec/unit/wrapper_gem_spec.rb
|
|
243
|
+
test_files: []
|
data/Gemfile
DELETED
|
@@ -1,33 +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
|
-
source 'https://rubygems.org'
|
|
19
|
-
|
|
20
|
-
# Specify your gem's dependencies in elasticsearch.gemspec
|
|
21
|
-
gemspec
|
|
22
|
-
|
|
23
|
-
if File.exist? File.expand_path("../../elasticsearch-api/elasticsearch-api.gemspec", __FILE__)
|
|
24
|
-
gem 'elasticsearch-api', :path => File.expand_path("../../elasticsearch-api", __FILE__), :require => false
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
if File.exist? File.expand_path("../../elasticsearch-transport/elasticsearch-transport.gemspec", __FILE__)
|
|
28
|
-
gem 'elasticsearch-transport', :path => File.expand_path("../../elasticsearch-transport", __FILE__), :require => false
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
if File.exist? File.expand_path("../../elasticsearch-extensions", __FILE__)
|
|
32
|
-
gem 'elasticsearch-extensions', :path => File.expand_path("../../elasticsearch-extensions", __FILE__), :require => true
|
|
33
|
-
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,97 +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 '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
|
|
@@ -1,57 +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 '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
|