elasticsearch 7.14.0 → 8.0.0.pre1

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.
@@ -0,0 +1,167 @@
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
+
20
+ describe Elasticsearch::Client do
21
+ context 'when cloud credentials are provided' do
22
+ let(:client) do
23
+ described_class.new(
24
+ cloud_id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==',
25
+ user: 'elastic',
26
+ password: 'changeme'
27
+ )
28
+ end
29
+
30
+ let(:hosts) do
31
+ client.transport.hosts
32
+ end
33
+
34
+ it 'extracts the cloud credentials' do
35
+ expect(hosts[0][:host]).to eq('abcd.localhost')
36
+ expect(hosts[0][:protocol]).to eq('https')
37
+ expect(hosts[0][:user]).to eq('elastic')
38
+ expect(hosts[0][:password]).to eq('changeme')
39
+ expect(hosts[0][:port]).to eq(443)
40
+ end
41
+
42
+ it 'creates the correct full url' do
43
+ expect(
44
+ client.transport.__full_url(client.transport.hosts[0])
45
+ ).to eq('https://elastic:changeme@abcd.localhost:443')
46
+ end
47
+
48
+ context 'when a port is specified' do
49
+ let(:client) do
50
+ described_class.new(cloud_id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==', user: 'elastic', password: 'changeme', port: 9250)
51
+ end
52
+
53
+ it 'sets the specified port along with the cloud credentials' do
54
+ expect(hosts[0][:host]).to eq('abcd.localhost')
55
+ expect(hosts[0][:protocol]).to eq('https')
56
+ expect(hosts[0][:user]).to eq('elastic')
57
+ expect(hosts[0][:password]).to eq('changeme')
58
+ expect(hosts[0][:port]).to eq(9250)
59
+ end
60
+
61
+ it 'creates the correct full url' do
62
+ expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://elastic:changeme@abcd.localhost:9250')
63
+ end
64
+ end
65
+
66
+ context 'when the cluster has alternate names' do
67
+ let(:client) do
68
+ described_class.new(
69
+ cloud_id: 'myCluster:bG9jYWxob3N0JGFiY2QkZWZnaA==',
70
+ user: 'elasticfantastic',
71
+ password: 'tobechanged'
72
+ )
73
+ end
74
+
75
+ let(:hosts) do
76
+ client.transport.hosts
77
+ end
78
+
79
+ it 'extracts the cloud credentials' do
80
+ expect(hosts[0][:host]).to eq('abcd.localhost')
81
+ expect(hosts[0][:protocol]).to eq('https')
82
+ expect(hosts[0][:user]).to eq('elasticfantastic')
83
+ expect(hosts[0][:password]).to eq('tobechanged')
84
+ expect(hosts[0][:port]).to eq(443)
85
+ end
86
+
87
+ it 'creates the correct full url' do
88
+ expect(
89
+ client.transport.__full_url(client.transport.hosts[0])
90
+ ).to eq('https://elasticfantastic:tobechanged@abcd.localhost:443')
91
+ end
92
+ end
93
+
94
+ context 'when decoded cloud id has a trailing dollar sign' do
95
+ let(:client) do
96
+ described_class.new(
97
+ cloud_id: 'a_cluster:bG9jYWxob3N0JGFiY2Qk',
98
+ user: 'elasticfantastic',
99
+ password: 'changeme'
100
+ )
101
+ end
102
+
103
+ let(:hosts) do
104
+ client.transport.hosts
105
+ end
106
+
107
+ it 'extracts the cloud credentials' do
108
+ expect(hosts[0][:host]).to eq('abcd.localhost')
109
+ expect(hosts[0][:protocol]).to eq('https')
110
+ expect(hosts[0][:user]).to eq('elasticfantastic')
111
+ expect(hosts[0][:password]).to eq('changeme')
112
+ expect(hosts[0][:port]).to eq(443)
113
+ end
114
+
115
+ it 'creates the correct full url' do
116
+ expect(
117
+ client.transport.__full_url(client.transport.hosts[0])
118
+ ).to eq('https://elasticfantastic:changeme@abcd.localhost:443')
119
+ end
120
+ end
121
+
122
+ context 'when the cloud host provides a port' do
123
+ let(:client) do
124
+ described_class.new(
125
+ cloud_id: 'name:ZWxhc3RpY19zZXJ2ZXI6OTI0MyRlbGFzdGljX2lk',
126
+ user: 'elastic',
127
+ password: 'changeme'
128
+ )
129
+ end
130
+
131
+ let(:hosts) do
132
+ client.transport.hosts
133
+ end
134
+
135
+ it 'creates the correct full url' do
136
+ expect(hosts[0][:host]).to eq('elastic_id.elastic_server')
137
+ expect(hosts[0][:protocol]).to eq('https')
138
+ expect(hosts[0][:user]).to eq('elastic')
139
+ expect(hosts[0][:password]).to eq('changeme')
140
+ expect(hosts[0][:port]).to eq(9243)
141
+ end
142
+ end
143
+
144
+ context 'when the cloud host provides a port and the port is also specified' do
145
+ let(:client) do
146
+ described_class.new(
147
+ cloud_id: 'name:ZWxhc3RpY19zZXJ2ZXI6OTI0MyRlbGFzdGljX2lk',
148
+ user: 'elastic',
149
+ password: 'changeme',
150
+ port: 9200
151
+ )
152
+ end
153
+
154
+ let(:hosts) do
155
+ client.transport.hosts
156
+ end
157
+
158
+ it 'creates the correct full url' do
159
+ expect(hosts[0][:host]).to eq('elastic_id.elastic_server')
160
+ expect(hosts[0][:protocol]).to eq('https')
161
+ expect(hosts[0][:user]).to eq('elastic')
162
+ expect(hosts[0][:password]).to eq('changeme')
163
+ expect(hosts[0][:port]).to eq(9243)
164
+ end
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,43 @@
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
+
19
+ describe Elasticsearch::Client do
20
+ context 'when using custom transport implementation' do
21
+ class MyTransport
22
+ include Elastic::Transport::Transport::Base
23
+ def initialize(args); end
24
+ end
25
+ let(:client) { Elasticsearch::Client.new(transport_class: MyTransport) }
26
+ let(:arguments) { client.instance_variable_get('@transport').instance_variable_get('@arguments') }
27
+ let(:subject) do
28
+ arguments[:transport_options][:headers]
29
+ end
30
+
31
+ let(:meta_header) do
32
+ if jruby?
33
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elastic::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION}"
34
+ else
35
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elastic::Transport::VERSION}"
36
+ end
37
+ end
38
+
39
+ it 'doesnae set any info about the implementation in the metaheader' do
40
+ expect(subject).to include('x-elastic-client-meta' => meta_header)
41
+ end
42
+ end
43
+ end
@@ -32,7 +32,7 @@ describe 'Elasticsearch: Validation' do
32
32
  let(:body) { {}.to_json }
33
33
  let(:client) { Elasticsearch::Client.new }
34
34
  let(:headers) do
35
- { 'content-type' => 'json' }
35
+ { 'content-type' => 'application/json' }
36
36
  end
37
37
 
38
38
  def error_requests_and_expectations(message = Elasticsearch::NOT_ELASTICSEARCH_WARNING)
@@ -96,9 +96,9 @@ describe 'Elasticsearch: Validation' do
96
96
  end
97
97
  end
98
98
 
99
- context 'When the Elasticsearch version is >= 7.14' do
99
+ context 'When the Elasticsearch version is >= 8.0.0' do
100
100
  context 'With a valid Elasticsearch response' do
101
- let(:body) { { 'version' => { 'number' => '7.14.0' } }.to_json }
101
+ let(:body) { { 'version' => { 'number' => '8.0.0' } }.to_json }
102
102
  let(:headers) do
103
103
  {
104
104
  'X-Elastic-Product' => 'Elasticsearch',
@@ -126,9 +126,9 @@ describe 'Elasticsearch: Validation' do
126
126
  end
127
127
  end
128
128
 
129
- context 'When the Elasticsearch version is >= 7.14-SNAPSHOT' do
129
+ context 'When the Elasticsearch version is >= 8.1.0' do
130
130
  context 'With a valid Elasticsearch response' do
131
- let(:body) { { 'version' => { 'number' => '7.14-SNAPSHOT' } }.to_json }
131
+ let(:body) { { 'version' => { 'number' => '8.1.0' } }.to_json }
132
132
  let(:headers) do
133
133
  {
134
134
  'X-Elastic-Product' => 'Elasticsearch',
@@ -156,15 +156,17 @@ describe 'Elasticsearch: Validation' do
156
156
  end
157
157
  end
158
158
 
159
- context 'When the Elasticsearch version is >= 7.15-SNAPSHOT' do
159
+
160
+ context 'When the Elasticsearch version is 8.0.0.pre' do
160
161
  context 'With a valid Elasticsearch response' do
161
- let(:body) { { 'version' => { 'number' => '7.15-SNAPSHOT' } }.to_json }
162
+ let(:body) { { 'version' => { 'number' => '8.0.0.pre' } }.to_json }
162
163
  let(:headers) do
163
164
  {
164
165
  'X-Elastic-Product' => 'Elasticsearch',
165
166
  'content-type' => 'json'
166
167
  }
167
168
  end
169
+
168
170
  it 'Makes requests and passes validation' do
169
171
  verify_request_stub
170
172
  count_request_stub
@@ -185,8 +187,8 @@ describe 'Elasticsearch: Validation' do
185
187
  end
186
188
  end
187
189
 
188
- context 'When the version is 7.x-SNAPSHOT' do
189
- let(:body) { { 'version' => { 'number' => '7.x-SNAPSHOT' } }.to_json }
190
+ context 'When the version is 8.0.0-SNAPSHOT' do
191
+ let(:body) { { 'version' => { 'number' => '8.0.0-SNAPSHOT' } }.to_json }
190
192
 
191
193
  context 'When the header is not present' do
192
194
  it 'Fails validation' do
@@ -214,77 +216,8 @@ describe 'Elasticsearch: Validation' do
214
216
  end
215
217
  end
216
218
 
217
- context 'When Elasticsearch version is 7.4.0' do
218
- context 'When tagline is not present' do
219
- let(:body) { { 'version' => { 'number' => '7.4.0', 'build_flavor' => 'default' } }.to_json }
220
-
221
- it 'Fails validation' do
222
- verify_request_stub
223
- count_request_stub
224
-
225
- error_requests_and_expectations
226
- end
227
- end
228
-
229
- context 'When build flavor is not present' do
230
- let(:body) do
231
- {
232
- 'version' => {
233
- 'number' => '7.4.0'
234
- },
235
- 'tagline' => Elasticsearch::YOU_KNOW_FOR_SEARCH
236
- }.to_json
237
- end
238
-
239
- it 'Fails validation' do
240
- verify_request_stub
241
- count_request_stub
242
-
243
- error_requests_and_expectations(Elasticsearch::NOT_SUPPORTED_ELASTICSEARCH_WARNING)
244
- end
245
- end
246
-
247
- context 'When the tagline is different' do
248
- let(:body) do
249
- {
250
- 'version' => {
251
- 'number' => '7.4.0',
252
- 'build_flavor' => 'default'
253
- },
254
- 'tagline' => 'You Know, for other stuff'
255
- }.to_json
256
- end
257
-
258
- it 'Fails validation' do
259
- verify_request_stub
260
- count_request_stub
261
-
262
- error_requests_and_expectations
263
- end
264
- end
265
-
266
- context 'With a valid Elasticsearch response' do
267
- let(:body) do
268
- {
269
- 'version' => {
270
- 'number' => '7.4.0',
271
- 'build_flavor' => 'default'
272
- },
273
- 'tagline' => 'You Know, for Search'
274
- }.to_json
275
- end
276
-
277
- it 'Makes requests and passes validation' do
278
- verify_request_stub
279
- count_request_stub
280
-
281
- valid_requests_and_expectations
282
- end
283
- end
284
- end
285
-
286
- context 'When Elasticsearch version is < 6.0.0' do
287
- let(:body) { { 'version' => { 'number' => '5.0.0' } }.to_json }
219
+ context 'When Elasticsearch version is < 8.0.0' do
220
+ let(:body) { { 'version' => { 'number' => '7.16.0' } }.to_json }
288
221
 
289
222
  it 'Raises an exception and client doesnae work' do
290
223
  verify_request_stub
@@ -300,141 +233,13 @@ describe 'Elasticsearch: Validation' do
300
233
  end
301
234
  end
302
235
 
303
- context 'When Elasticsearch version is between 6.0.0 and 7.0.0' do
304
- context 'With an Elasticsearch valid response' do
305
- let(:body) do
306
- {
307
- 'version' => {
308
- 'number' => '6.8.10'
309
- },
310
- 'tagline' => 'You Know, for Search'
311
- }.to_json
312
- end
313
-
314
- it 'Makes requests and passes validation' do
315
- verify_request_stub
316
- count_request_stub
317
-
318
- valid_requests_and_expectations
319
- end
320
- end
321
-
322
- context 'With no tagline' do
323
- let(:body) do
324
- { 'version' => { 'number' => '6.8.10' } }.to_json
325
- end
326
-
327
- it 'Fails validation' do
328
- verify_request_stub
329
- count_request_stub
330
-
331
- error_requests_and_expectations
332
- end
333
- end
334
-
335
- context 'When the tagline is different' do
336
- let(:body) do
337
- {
338
- 'version' => {
339
- 'number' => '6.8.10',
340
- 'build_flavor' => 'default'
341
- },
342
- 'tagline' => 'You Know, for Stuff'
343
- }.to_json
344
- end
345
-
346
- it 'Fails validation' do
347
- verify_request_stub
348
- count_request_stub
349
-
350
- error_requests_and_expectations
351
- end
352
- end
353
- end
354
-
355
- context 'When Elasticsearch version is between 7.0.0 and 7.14.0' do
356
- context 'With a valid Elasticsearch response' do
357
- let(:body) do
358
- {
359
- 'version' => {
360
- 'number' => '7.10.0',
361
- 'build_flavor' => 'default'
362
- },
363
- 'tagline' => 'You Know, for Search'
364
- }.to_json
365
- end
366
-
367
- it 'Makes requests and passes validation' do
368
- verify_request_stub
369
- count_request_stub
370
-
371
- valid_requests_and_expectations
372
- end
373
- end
374
-
375
- context 'When the tagline is not present' do
376
- let(:body) do
377
- {
378
- 'version' => {
379
- 'number' => '7.10.0',
380
- 'build_flavor' => 'default'
381
- }
382
- }.to_json
383
- end
384
-
385
- it 'Fails validation' do
386
- verify_request_stub
387
- count_request_stub
388
-
389
- error_requests_and_expectations
390
- end
391
- end
392
-
393
- context 'When the tagline is different' do
394
- let(:body) do
395
- {
396
- 'version' => {
397
- 'number' => '7.10.0',
398
- 'build_flavor' => 'default'
399
- },
400
- 'tagline' => 'You Know, for other stuff'
401
- }.to_json
402
- end
403
-
404
- it 'Fails validation' do
405
- verify_request_stub
406
- count_request_stub
407
-
408
- error_requests_and_expectations
409
- end
410
- end
411
-
412
- context 'When the build_flavor is not present' do
413
- let(:body) do
414
- {
415
- 'version' => {
416
- 'number' => '7.10.0'
417
- },
418
- 'tagline' => 'You Know, for Search'
419
- }.to_json
420
- end
421
-
422
- it 'Fails validation' do
423
- verify_request_stub
424
- count_request_stub
425
-
426
- error_requests_and_expectations(Elasticsearch::NOT_SUPPORTED_ELASTICSEARCH_WARNING)
427
- end
428
- end
429
- end
430
-
431
236
  context 'When doing a yaml content-type request' do
432
237
  let(:client) do
433
238
  Elasticsearch::Client.new(transport_options: {headers: { accept: 'application/yaml', content_type: 'application/yaml' }})
434
239
  end
435
240
 
436
241
  let(:headers) { { 'content-type' => 'application/yaml', 'X-Elastic-Product' => 'Elasticsearch' } }
437
- let(:body) { "---\nversion:\n number: \"7.14.0-SNAPSHOT\"\n" }
242
+ let(:body) { "---\nversion:\n number: \"8.0.0-SNAPSHOT\"\n" }
438
243
 
439
244
  it 'validates' do
440
245
  verify_request_stub
@@ -0,0 +1,55 @@
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 'ostruct'
19
+
20
+ describe Elasticsearch::Client do
21
+ context 'when a header is set on an endpoint request' do
22
+ let(:client) { described_class.new }
23
+ let(:headers) { { 'user-agent' => 'my ruby app' } }
24
+
25
+ it 'performs the request with the header' do
26
+ allow(client).to receive(:perform_request) { OpenStruct.new(body: '') }
27
+ expect { client.search(headers: headers) }.not_to raise_error
28
+ expect(client).to have_received(:perform_request)
29
+ .with('GET', '_search', {}, nil, headers)
30
+ end
31
+ end
32
+
33
+ context 'when a header is set on an endpoint request and on initialization' do
34
+ let!(:client) do
35
+ described_class.new(
36
+ host: 'http://localhost:9200',
37
+ transport_options: { headers: instance_headers }
38
+ ).tap do |client|
39
+ client.instance_variable_set('@verified', true)
40
+ end
41
+ end
42
+ let(:instance_headers) { { set_in_instantiation: 'header value' } }
43
+ let(:param_headers) { { 'user-agent' => 'My Ruby Tests', 'set-on-method-call' => 'header value' } }
44
+
45
+ it 'performs the request with the header' do
46
+ expected_headers = client.transport.connections.connections.first.connection.headers.merge(param_headers)
47
+
48
+ expect_any_instance_of(Faraday::Connection)
49
+ .to receive(:run_request)
50
+ .with(:get, 'http://localhost:9200/_search', nil, expected_headers) { OpenStruct.new(body: '') }
51
+
52
+ client.search(headers: param_headers)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,48 @@
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 'ostruct'
19
+
20
+ describe Elasticsearch::Client do
21
+ let(:transport) { client.instance_variable_get('@transport') }
22
+ let(:client) { described_class.new.tap { |cl| cl.instance_variable_set('@verified', true) } }
23
+
24
+ before do
25
+ allow(transport).to receive(:perform_request) { OpenStruct.new(body: '') }
26
+ end
27
+
28
+ context 'when x-opaque-id is set' do
29
+ it 'uses x-opaque-id on a request' do
30
+ client.search(opaque_id: '12345')
31
+ expect(transport).to have_received(:perform_request)
32
+ .with('GET', '_search', {}, nil, { 'X-Opaque-Id' => '12345' })
33
+ end
34
+ end
35
+
36
+ context 'when an x-opaque-id prefix is set on initialization' do
37
+ let(:prefix) { 'elastic_cloud' }
38
+ let(:client) do
39
+ described_class.new(opaque_id_prefix: prefix).tap { |cl| cl.instance_variable_set('@verified', true) }
40
+ end
41
+
42
+ it 'uses x-opaque-id on a request' do
43
+ expect { client.search(opaque_id: '12345') }.not_to raise_error
44
+ expect(transport).to have_received(:perform_request)
45
+ .with('GET', '_search', {}, nil, { 'X-Opaque-Id' => 'elastic_cloud12345' })
46
+ end
47
+ end
48
+ end
@@ -14,13 +14,13 @@
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
- require 'elasticsearch'
18
- require 'webmock/rspec'
17
+
18
+ require 'spec_helper'
19
19
 
20
20
  describe 'Elasticsearch: wrapper gem' do
21
21
  it 'requires all neccessary subgems' do
22
- expect(defined?(Elasticsearch::Client))
23
- expect(defined?(Elasticsearch::API))
22
+ expect(defined? Elasticsearch::Client)
23
+ expect(defined? Elasticsearch::API)
24
24
  end
25
25
 
26
26
  it 'mixes the API into the client' do
@@ -30,10 +30,4 @@ describe 'Elasticsearch: wrapper gem' do
30
30
  expect(client).to respond_to(:cluster)
31
31
  expect(client).to respond_to(:indices)
32
32
  end
33
-
34
- it 'can access the client transport' do
35
- client = Elasticsearch::Client.new
36
- expect(client.transport).to be_a(Elasticsearch::Transport::Client)
37
- expect(client.transport.transport).to be_a(Elasticsearch::Transport::Transport::HTTP::Faraday)
38
- end
39
33
  end