elasticsearch-persistence 7.2.1 → 8.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +4 -3
- data/Rakefile +8 -7
- data/elasticsearch-persistence.gemspec +32 -35
- data/examples/notes/application.rb +0 -1
- data/examples/notes/test.rb +1 -1
- data/lib/elasticsearch/persistence/repository/dsl.rb +0 -14
- data/lib/elasticsearch/persistence/repository/find.rb +1 -4
- data/lib/elasticsearch/persistence/repository/search.rb +2 -4
- data/lib/elasticsearch/persistence/repository/store.rb +6 -9
- data/lib/elasticsearch/persistence/repository.rb +1 -17
- data/lib/elasticsearch/persistence/version.rb +1 -1
- data/spec/repository/find_spec.rb +14 -91
- data/spec/repository/response/results_spec.rb +18 -17
- data/spec/repository/search_spec.rb +27 -153
- data/spec/repository/store_spec.rb +8 -48
- data/spec/repository_spec.rb +50 -145
- data/spec/spec_helper.rb +3 -2
- metadata +55 -55
data/spec/repository_spec.rb
CHANGED
@@ -18,9 +18,7 @@
|
|
18
18
|
require 'spec_helper'
|
19
19
|
|
20
20
|
describe Elasticsearch::Persistence::Repository do
|
21
|
-
|
22
21
|
describe '#create' do
|
23
|
-
|
24
22
|
before(:all) do
|
25
23
|
class RepositoryWithoutDSL
|
26
24
|
include Elasticsearch::Persistence::Repository
|
@@ -37,21 +35,9 @@ describe Elasticsearch::Persistence::Repository do
|
|
37
35
|
expect(RepositoryWithoutDSL.create).to be_a(RepositoryWithoutDSL)
|
38
36
|
end
|
39
37
|
|
40
|
-
context 'when options are provided' do
|
41
|
-
|
42
|
-
let(:repository) do
|
43
|
-
RepositoryWithoutDSL.create(document_type: 'note')
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'sets the options on the instance' do
|
47
|
-
expect(repository.document_type).to eq('note')
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
38
|
context 'when a block is passed' do
|
52
|
-
|
53
39
|
let(:repository) do
|
54
|
-
RepositoryWithoutDSL.create
|
40
|
+
RepositoryWithoutDSL.create do
|
55
41
|
mapping dynamic: 'strict' do
|
56
42
|
indexes :foo
|
57
43
|
end
|
@@ -59,13 +45,12 @@ describe Elasticsearch::Persistence::Repository do
|
|
59
45
|
end
|
60
46
|
|
61
47
|
it 'executes the block on the instance' do
|
62
|
-
expect(repository.mapping.to_hash).to eq(
|
48
|
+
expect(repository.mapping.to_hash).to eq({ dynamic: 'strict', properties: { foo: { type: 'text' } } })
|
63
49
|
end
|
64
50
|
|
65
51
|
context 'when options are provided in the args and set in the block' do
|
66
|
-
|
67
52
|
let(:repository) do
|
68
|
-
RepositoryWithoutDSL.create(mapping: double('mapping', to_hash: {})
|
53
|
+
RepositoryWithoutDSL.create(mapping: double('mapping', to_hash: {})) do
|
69
54
|
mapping dynamic: 'strict' do
|
70
55
|
indexes :foo
|
71
56
|
end
|
@@ -80,7 +65,6 @@ describe Elasticsearch::Persistence::Repository do
|
|
80
65
|
end
|
81
66
|
|
82
67
|
describe '#initialize' do
|
83
|
-
|
84
68
|
before(:all) do
|
85
69
|
class RepositoryWithoutDSL
|
86
70
|
include Elasticsearch::Persistence::Repository
|
@@ -98,7 +82,6 @@ describe Elasticsearch::Persistence::Repository do
|
|
98
82
|
end
|
99
83
|
|
100
84
|
context 'when options are not provided' do
|
101
|
-
|
102
85
|
let(:repository) do
|
103
86
|
RepositoryWithoutDSL.new
|
104
87
|
end
|
@@ -118,23 +101,18 @@ describe Elasticsearch::Persistence::Repository do
|
|
118
101
|
end
|
119
102
|
|
120
103
|
context 'when options are provided' do
|
121
|
-
|
122
104
|
let(:client) do
|
123
105
|
Elasticsearch::Client.new
|
124
106
|
end
|
125
107
|
|
126
108
|
let(:repository) do
|
127
|
-
RepositoryWithoutDSL.new(client: client,
|
109
|
+
RepositoryWithoutDSL.new(client: client, index_name: 'users', klass: Array)
|
128
110
|
end
|
129
111
|
|
130
112
|
it 'sets the client' do
|
131
113
|
expect(repository.client).to be(client)
|
132
114
|
end
|
133
115
|
|
134
|
-
it 'sets document type' do
|
135
|
-
expect(repository.document_type).to eq('user')
|
136
|
-
end
|
137
|
-
|
138
116
|
it 'sets index name' do
|
139
117
|
expect(repository.index_name).to eq('users')
|
140
118
|
end
|
@@ -146,13 +124,11 @@ describe Elasticsearch::Persistence::Repository do
|
|
146
124
|
end
|
147
125
|
|
148
126
|
context 'when the DSL module is included' do
|
149
|
-
|
150
127
|
before(:all) do
|
151
128
|
class RepositoryWithDSL
|
152
129
|
include Elasticsearch::Persistence::Repository
|
153
130
|
include Elasticsearch::Persistence::Repository::DSL
|
154
131
|
|
155
|
-
document_type 'note'
|
156
132
|
index_name 'notes_repo'
|
157
133
|
klass Hash
|
158
134
|
client DEFAULT_CLIENT
|
@@ -179,7 +155,6 @@ describe Elasticsearch::Persistence::Repository do
|
|
179
155
|
end
|
180
156
|
|
181
157
|
context '#client' do
|
182
|
-
|
183
158
|
it 'allows the value to be set only once on the class' do
|
184
159
|
RepositoryWithDSL.client(double('client', class: 'other_client'))
|
185
160
|
expect(RepositoryWithDSL.client).to be(DEFAULT_CLIENT)
|
@@ -199,7 +174,6 @@ describe Elasticsearch::Persistence::Repository do
|
|
199
174
|
end
|
200
175
|
|
201
176
|
context '#klass' do
|
202
|
-
|
203
177
|
it 'allows the value to be set only once on the class' do
|
204
178
|
RepositoryWithDSL.klass(Array)
|
205
179
|
expect(RepositoryWithDSL.klass).to eq(Hash)
|
@@ -229,28 +203,7 @@ describe Elasticsearch::Persistence::Repository do
|
|
229
203
|
end
|
230
204
|
end
|
231
205
|
|
232
|
-
context '#document_type' do
|
233
|
-
|
234
|
-
it 'allows the value to be set only once on the class' do
|
235
|
-
RepositoryWithDSL.document_type('other_note')
|
236
|
-
expect(RepositoryWithDSL.document_type).to eq('note')
|
237
|
-
end
|
238
|
-
|
239
|
-
it 'sets the value at the class level' do
|
240
|
-
expect(RepositoryWithDSL.document_type).to eq('note')
|
241
|
-
end
|
242
|
-
|
243
|
-
it 'sets the value as the default at the instance level' do
|
244
|
-
expect(RepositoryWithDSL.new.document_type).to eq('note')
|
245
|
-
end
|
246
|
-
|
247
|
-
it 'allows the value to be overridden with options on the instance' do
|
248
|
-
expect(RepositoryWithDSL.new(document_type: 'other_note').document_type).to eq('other_note')
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
206
|
context '#index_name' do
|
253
|
-
|
254
207
|
it 'allows the value to be set only once on the class' do
|
255
208
|
RepositoryWithDSL.index_name('other_name')
|
256
209
|
expect(RepositoryWithDSL.index_name).to eq('notes_repo')
|
@@ -270,16 +223,14 @@ describe Elasticsearch::Persistence::Repository do
|
|
270
223
|
end
|
271
224
|
|
272
225
|
describe '#create_index!' do
|
273
|
-
|
274
226
|
context 'when the method is called on an instance' do
|
275
|
-
|
276
227
|
let(:repository) do
|
277
228
|
RepositoryWithDSL.new
|
278
229
|
end
|
279
230
|
|
280
231
|
before do
|
281
232
|
begin; repository.delete_index!; rescue; end
|
282
|
-
repository.create_index!
|
233
|
+
repository.create_index!
|
283
234
|
end
|
284
235
|
|
285
236
|
it 'creates the index' do
|
@@ -288,7 +239,6 @@ describe Elasticsearch::Persistence::Repository do
|
|
288
239
|
end
|
289
240
|
|
290
241
|
context 'when the method is called on the class' do
|
291
|
-
|
292
242
|
it 'raises a NotImplementedError' do
|
293
243
|
expect {
|
294
244
|
RepositoryWithDSL.create_index!
|
@@ -298,9 +248,7 @@ describe Elasticsearch::Persistence::Repository do
|
|
298
248
|
end
|
299
249
|
|
300
250
|
describe '#delete_index!' do
|
301
|
-
|
302
251
|
context 'when the method is called on an instance' do
|
303
|
-
|
304
252
|
let(:repository) do
|
305
253
|
RepositoryWithDSL.new
|
306
254
|
end
|
@@ -316,7 +264,6 @@ describe Elasticsearch::Persistence::Repository do
|
|
316
264
|
end
|
317
265
|
|
318
266
|
context 'when the method is called on the class' do
|
319
|
-
|
320
267
|
it 'raises a NotImplementedError' do
|
321
268
|
expect {
|
322
269
|
RepositoryWithDSL.delete_index!
|
@@ -326,15 +273,13 @@ describe Elasticsearch::Persistence::Repository do
|
|
326
273
|
end
|
327
274
|
|
328
275
|
describe '#refresh_index!' do
|
329
|
-
|
330
276
|
context 'when the method is called on an instance' do
|
331
|
-
|
332
277
|
let(:repository) do
|
333
278
|
RepositoryWithDSL.new
|
334
279
|
end
|
335
280
|
|
336
281
|
before do
|
337
|
-
repository.create_index!
|
282
|
+
repository.create_index!
|
338
283
|
end
|
339
284
|
|
340
285
|
it 'refreshes the index' do
|
@@ -343,7 +288,6 @@ describe Elasticsearch::Persistence::Repository do
|
|
343
288
|
end
|
344
289
|
|
345
290
|
context 'when the method is called on the class' do
|
346
|
-
|
347
291
|
it 'raises a NotImplementedError' do
|
348
292
|
expect {
|
349
293
|
RepositoryWithDSL.refresh_index!
|
@@ -353,15 +297,13 @@ describe Elasticsearch::Persistence::Repository do
|
|
353
297
|
end
|
354
298
|
|
355
299
|
describe '#index_exists?' do
|
356
|
-
|
357
300
|
context 'when the method is called on an instance' do
|
358
|
-
|
359
301
|
let(:repository) do
|
360
302
|
RepositoryWithDSL.new
|
361
303
|
end
|
362
304
|
|
363
305
|
before do
|
364
|
-
repository.create_index!
|
306
|
+
repository.create_index!
|
365
307
|
end
|
366
308
|
|
367
309
|
it 'determines if the index exists' do
|
@@ -377,7 +319,6 @@ describe Elasticsearch::Persistence::Repository do
|
|
377
319
|
end
|
378
320
|
|
379
321
|
context 'when the method is called on the class' do
|
380
|
-
|
381
322
|
it 'raises a NotImplementedError' do
|
382
323
|
expect {
|
383
324
|
RepositoryWithDSL.index_exists?
|
@@ -387,13 +328,15 @@ describe Elasticsearch::Persistence::Repository do
|
|
387
328
|
end
|
388
329
|
|
389
330
|
describe '#mapping' do
|
390
|
-
|
391
331
|
let(:expected_mapping) do
|
392
|
-
{
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
332
|
+
{
|
333
|
+
dynamic: 'strict',
|
334
|
+
properties: {
|
335
|
+
foo: {
|
336
|
+
type: 'object',
|
337
|
+
properties: { bar: { type: 'text' } } },
|
338
|
+
baz: { type: 'text' }
|
339
|
+
}
|
397
340
|
}
|
398
341
|
end
|
399
342
|
|
@@ -410,24 +353,25 @@ describe Elasticsearch::Persistence::Repository do
|
|
410
353
|
end
|
411
354
|
|
412
355
|
context 'when the instance has a different document type' do
|
413
|
-
|
414
356
|
let(:expected_mapping) do
|
415
|
-
{
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
357
|
+
{
|
358
|
+
other_note:
|
359
|
+
{
|
360
|
+
dynamic: 'strict',
|
361
|
+
properties: {
|
362
|
+
foo: {
|
363
|
+
type: 'object',
|
364
|
+
properties: { bar: { type: 'text' } }
|
365
|
+
},
|
366
|
+
baz: { type: 'text' }
|
367
|
+
}
|
368
|
+
}
|
420
369
|
}
|
421
370
|
end
|
422
|
-
|
423
|
-
it 'updates the mapping to use the document type' do
|
424
|
-
expect(RepositoryWithDSL.new(document_type: 'other_note').mapping.to_hash).to eq(expected_mapping)
|
425
|
-
end
|
426
371
|
end
|
427
372
|
end
|
428
373
|
|
429
374
|
describe '#settings' do
|
430
|
-
|
431
375
|
it 'sets the value at the class level' do
|
432
376
|
expect(RepositoryWithDSL.settings.to_hash).to eq(number_of_shards: 1, number_of_replicas: 0)
|
433
377
|
end
|
@@ -443,7 +387,6 @@ describe Elasticsearch::Persistence::Repository do
|
|
443
387
|
end
|
444
388
|
|
445
389
|
context 'when the DSL module is not included' do
|
446
|
-
|
447
390
|
before(:all) do
|
448
391
|
class RepositoryWithoutDSL
|
449
392
|
include Elasticsearch::Persistence::Repository
|
@@ -490,21 +433,8 @@ describe Elasticsearch::Persistence::Repository do
|
|
490
433
|
end
|
491
434
|
end
|
492
435
|
|
493
|
-
context '#document_type' do
|
494
|
-
|
495
|
-
it 'does not define the method at the class level' do
|
496
|
-
expect {
|
497
|
-
RepositoryWithoutDSL.document_type
|
498
|
-
}.to raise_exception(NoMethodError)
|
499
|
-
end
|
500
|
-
|
501
|
-
it 'allows the value to be overridden with options on the instance' do
|
502
|
-
expect(RepositoryWithoutDSL.new(document_type: 'notes').document_type).to eq('notes')
|
503
|
-
end
|
504
|
-
end
|
505
436
|
|
506
437
|
context '#index_name' do
|
507
|
-
|
508
438
|
it 'does not define the method at the class level' do
|
509
439
|
expect {
|
510
440
|
RepositoryWithoutDSL.index_name
|
@@ -521,7 +451,6 @@ describe Elasticsearch::Persistence::Repository do
|
|
521
451
|
end
|
522
452
|
|
523
453
|
describe '#create_index!' do
|
524
|
-
|
525
454
|
let(:repository) do
|
526
455
|
RepositoryWithoutDSL.new(client: DEFAULT_CLIENT)
|
527
456
|
end
|
@@ -540,37 +469,9 @@ describe Elasticsearch::Persistence::Repository do
|
|
540
469
|
repository.create_index!
|
541
470
|
expect(repository.index_exists?).to eq(true)
|
542
471
|
end
|
543
|
-
|
544
|
-
context 'when the repository has a document type defined' do
|
545
|
-
|
546
|
-
let(:repository) do
|
547
|
-
RepositoryWithoutDSL.new(client: DEFAULT_CLIENT, document_type: 'mytype')
|
548
|
-
end
|
549
|
-
|
550
|
-
context 'when the server is version >= 7.0', if: server_version > '7.0' do
|
551
|
-
|
552
|
-
context 'when the include_type_name option is specified' do
|
553
|
-
|
554
|
-
it 'creates an index' do
|
555
|
-
repository.create_index!(include_type_name: true)
|
556
|
-
expect(repository.index_exists?).to eq(true)
|
557
|
-
end
|
558
|
-
end
|
559
|
-
|
560
|
-
context 'when the include_type_name option is not specified' do
|
561
|
-
|
562
|
-
it 'raises an error' do
|
563
|
-
expect {
|
564
|
-
repository.create_index!
|
565
|
-
}.to raise_exception(Elasticsearch::Transport::Transport::Errors::BadRequest)
|
566
|
-
end
|
567
|
-
end
|
568
|
-
end
|
569
|
-
end
|
570
472
|
end
|
571
473
|
|
572
474
|
describe '#delete_index!' do
|
573
|
-
|
574
475
|
let(:repository) do
|
575
476
|
RepositoryWithoutDSL.new(client: DEFAULT_CLIENT)
|
576
477
|
end
|
@@ -582,14 +483,13 @@ describe Elasticsearch::Persistence::Repository do
|
|
582
483
|
end
|
583
484
|
|
584
485
|
it 'deletes an index' do
|
585
|
-
repository.create_index!
|
486
|
+
repository.create_index!
|
586
487
|
repository.delete_index!
|
587
488
|
expect(repository.index_exists?).to eq(false)
|
588
489
|
end
|
589
490
|
end
|
590
491
|
|
591
492
|
describe '#refresh_index!' do
|
592
|
-
|
593
493
|
let(:repository) do
|
594
494
|
RepositoryWithoutDSL.new(client: DEFAULT_CLIENT)
|
595
495
|
end
|
@@ -605,7 +505,7 @@ describe Elasticsearch::Persistence::Repository do
|
|
605
505
|
end
|
606
506
|
|
607
507
|
it 'refreshes an index' do
|
608
|
-
repository.create_index!
|
508
|
+
repository.create_index!
|
609
509
|
expect(repository.refresh_index!['_shards']).to be_a(Hash)
|
610
510
|
end
|
611
511
|
end
|
@@ -627,7 +527,7 @@ describe Elasticsearch::Persistence::Repository do
|
|
627
527
|
end
|
628
528
|
|
629
529
|
it 'returns whether the index exists' do
|
630
|
-
repository.create_index!
|
530
|
+
repository.create_index!
|
631
531
|
expect(repository.index_exists?).to be(true)
|
632
532
|
end
|
633
533
|
end
|
@@ -651,16 +551,20 @@ describe Elasticsearch::Persistence::Repository do
|
|
651
551
|
context 'when a block is passed to the create method' do
|
652
552
|
|
653
553
|
let(:expected_mapping) do
|
654
|
-
{
|
655
|
-
|
656
|
-
|
657
|
-
|
554
|
+
{
|
555
|
+
dynamic: 'strict',
|
556
|
+
properties: {
|
557
|
+
foo: {
|
558
|
+
type: 'object',
|
559
|
+
properties: { bar: { type: 'text' } }
|
560
|
+
},
|
561
|
+
baz: { type: 'text' }
|
658
562
|
}
|
659
563
|
}
|
660
564
|
end
|
661
565
|
|
662
566
|
let(:repository) do
|
663
|
-
RepositoryWithoutDSL.create
|
567
|
+
RepositoryWithoutDSL.create do
|
664
568
|
mapping dynamic: 'strict' do
|
665
569
|
indexes :foo do
|
666
570
|
indexes :bar
|
@@ -695,7 +599,6 @@ describe Elasticsearch::Persistence::Repository do
|
|
695
599
|
end
|
696
600
|
|
697
601
|
describe '#settings' do
|
698
|
-
|
699
602
|
it 'does not define the method at the class level' do
|
700
603
|
expect {
|
701
604
|
RepositoryWithoutDSL.settings
|
@@ -711,9 +614,8 @@ describe Elasticsearch::Persistence::Repository do
|
|
711
614
|
end
|
712
615
|
|
713
616
|
context 'when a block is passed to the #create method' do
|
714
|
-
|
715
617
|
let(:repository) do
|
716
|
-
RepositoryWithoutDSL.create
|
618
|
+
RepositoryWithoutDSL.create do
|
717
619
|
settings number_of_shards: 1, number_of_replicas: 0
|
718
620
|
end
|
719
621
|
end
|
@@ -723,18 +625,21 @@ describe Elasticsearch::Persistence::Repository do
|
|
723
625
|
end
|
724
626
|
|
725
627
|
context 'when a mapping is set in the block as well' do
|
726
|
-
|
727
628
|
let(:expected_mapping) do
|
728
|
-
{
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
629
|
+
{
|
630
|
+
dynamic: 'strict',
|
631
|
+
properties: {
|
632
|
+
foo: {
|
633
|
+
type: 'object',
|
634
|
+
properties: { bar: { type: 'text' } }
|
635
|
+
},
|
636
|
+
baz: { type: 'text' }
|
637
|
+
}
|
733
638
|
}
|
734
639
|
end
|
735
640
|
|
736
641
|
let(:repository) do
|
737
|
-
RepositoryWithoutDSL.create
|
642
|
+
RepositoryWithoutDSL.create do
|
738
643
|
settings number_of_shards: 1, number_of_replicas: 0 do
|
739
644
|
mapping dynamic: 'strict' do
|
740
645
|
indexes :foo do
|
data/spec/spec_helper.rb
CHANGED
@@ -36,7 +36,8 @@ end
|
|
36
36
|
#
|
37
37
|
# @since 6.0.0
|
38
38
|
DEFAULT_CLIENT = Elasticsearch::Client.new(host: ELASTICSEARCH_URL,
|
39
|
-
tracer: (ENV['QUIET'] ? nil : ::Logger.new(STDERR))
|
39
|
+
tracer: (ENV['QUIET'] ? nil : ::Logger.new(STDERR)),
|
40
|
+
transport_options: { :ssl => { verify: false } })
|
40
41
|
|
41
42
|
class MyTestRepository
|
42
43
|
include Elasticsearch::Persistence::Repository
|
@@ -47,7 +48,7 @@ end
|
|
47
48
|
# The default repository to be used by tests.
|
48
49
|
#
|
49
50
|
# @since 6.0.0
|
50
|
-
DEFAULT_REPOSITORY = MyTestRepository.new(index_name: 'my_test_repository'
|
51
|
+
DEFAULT_REPOSITORY = MyTestRepository.new(index_name: 'my_test_repository')
|
51
52
|
|
52
53
|
# Get the Elasticsearch server version.
|
53
54
|
#
|