chewy 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +24 -2
- data/.rubocop_todo.yml +2 -2
- data/.travis.yml +38 -21
- data/.yardopts +5 -0
- data/Appraisals +55 -27
- data/CHANGELOG.md +57 -12
- data/Gemfile +14 -10
- data/LEGACY_DSL.md +497 -0
- data/README.md +249 -515
- data/chewy.gemspec +5 -4
- data/gemfiles/rails.4.0.activerecord.gemfile +14 -0
- data/gemfiles/rails.4.1.activerecord.gemfile +14 -0
- data/gemfiles/rails.4.2.activerecord.gemfile +8 -10
- data/gemfiles/rails.4.2.mongoid.5.1.gemfile +9 -10
- data/gemfiles/rails.5.0.activerecord.gemfile +8 -10
- data/gemfiles/rails.5.0.mongoid.6.0.gemfile +15 -0
- data/gemfiles/rails.5.1.activerecord.gemfile +15 -0
- data/gemfiles/rails.5.1.mongoid.6.1.gemfile +15 -0
- data/gemfiles/sequel.4.45.gemfile +11 -0
- data/lib/chewy.rb +77 -43
- data/lib/chewy/config.rb +44 -7
- data/lib/chewy/errors.rb +2 -2
- data/lib/chewy/fields/base.rb +39 -32
- data/lib/chewy/fields/root.rb +33 -7
- data/lib/chewy/index.rb +237 -149
- data/lib/chewy/index/actions.rb +85 -28
- data/lib/chewy/index/aliases.rb +2 -1
- data/lib/chewy/index/settings.rb +9 -5
- data/lib/chewy/index/specification.rb +58 -0
- data/lib/chewy/journal.rb +40 -92
- data/lib/chewy/query.rb +43 -27
- data/lib/chewy/query/compose.rb +13 -13
- data/lib/chewy/query/criteria.rb +13 -13
- data/lib/chewy/query/filters.rb +1 -1
- data/lib/chewy/query/loading.rb +1 -1
- data/lib/chewy/query/nodes/and.rb +2 -2
- data/lib/chewy/query/nodes/bool.rb +1 -1
- data/lib/chewy/query/nodes/equal.rb +2 -2
- data/lib/chewy/query/nodes/exists.rb +1 -1
- data/lib/chewy/query/nodes/has_relation.rb +2 -2
- data/lib/chewy/query/nodes/match_all.rb +1 -1
- data/lib/chewy/query/nodes/missing.rb +1 -1
- data/lib/chewy/query/nodes/not.rb +2 -2
- data/lib/chewy/query/nodes/or.rb +2 -2
- data/lib/chewy/query/nodes/prefix.rb +1 -1
- data/lib/chewy/query/nodes/query.rb +2 -2
- data/lib/chewy/query/nodes/range.rb +4 -4
- data/lib/chewy/query/nodes/regexp.rb +4 -4
- data/lib/chewy/query/nodes/script.rb +3 -3
- data/lib/chewy/query/pagination.rb +10 -1
- data/lib/chewy/railtie.rb +1 -0
- data/lib/chewy/rake_helper.rb +265 -48
- data/lib/chewy/rspec/update_index.rb +30 -22
- data/lib/chewy/search.rb +78 -21
- data/lib/chewy/search/loader.rb +83 -0
- data/lib/chewy/{query → search}/pagination/kaminari.rb +13 -5
- data/lib/chewy/search/pagination/will_paginate.rb +41 -0
- data/lib/chewy/search/parameters.rb +150 -0
- data/lib/chewy/search/parameters/aggs.rb +16 -0
- data/lib/chewy/search/parameters/concerns/bool_storage.rb +24 -0
- data/lib/chewy/search/parameters/concerns/hash_storage.rb +23 -0
- data/lib/chewy/search/parameters/concerns/integer_storage.rb +14 -0
- data/lib/chewy/search/parameters/concerns/query_storage.rb +237 -0
- data/lib/chewy/search/parameters/concerns/string_array_storage.rb +23 -0
- data/lib/chewy/search/parameters/concerns/string_storage.rb +14 -0
- data/lib/chewy/search/parameters/docvalue_fields.rb +12 -0
- data/lib/chewy/search/parameters/explain.rb +16 -0
- data/lib/chewy/search/parameters/filter.rb +47 -0
- data/lib/chewy/search/parameters/highlight.rb +16 -0
- data/lib/chewy/search/parameters/indices_boost.rb +52 -0
- data/lib/chewy/search/parameters/limit.rb +17 -0
- data/lib/chewy/search/parameters/load.rb +32 -0
- data/lib/chewy/search/parameters/min_score.rb +16 -0
- data/lib/chewy/search/parameters/none.rb +27 -0
- data/lib/chewy/search/parameters/offset.rb +17 -0
- data/lib/chewy/search/parameters/order.rb +64 -0
- data/lib/chewy/search/parameters/post_filter.rb +19 -0
- data/lib/chewy/search/parameters/preference.rb +16 -0
- data/lib/chewy/search/parameters/profile.rb +16 -0
- data/lib/chewy/search/parameters/query.rb +19 -0
- data/lib/chewy/search/parameters/request_cache.rb +27 -0
- data/lib/chewy/search/parameters/rescore.rb +29 -0
- data/lib/chewy/search/parameters/script_fields.rb +16 -0
- data/lib/chewy/search/parameters/search_after.rb +20 -0
- data/lib/chewy/search/parameters/search_type.rb +16 -0
- data/lib/chewy/search/parameters/source.rb +73 -0
- data/lib/chewy/search/parameters/storage.rb +95 -0
- data/lib/chewy/search/parameters/stored_fields.rb +63 -0
- data/lib/chewy/search/parameters/suggest.rb +16 -0
- data/lib/chewy/search/parameters/terminate_after.rb +16 -0
- data/lib/chewy/search/parameters/timeout.rb +16 -0
- data/lib/chewy/search/parameters/track_scores.rb +16 -0
- data/lib/chewy/search/parameters/types.rb +20 -0
- data/lib/chewy/search/parameters/version.rb +16 -0
- data/lib/chewy/search/query_proxy.rb +257 -0
- data/lib/chewy/search/request.rb +1021 -0
- data/lib/chewy/search/response.rb +119 -0
- data/lib/chewy/search/scoping.rb +50 -0
- data/lib/chewy/search/scrolling.rb +136 -0
- data/lib/chewy/stash.rb +70 -0
- data/lib/chewy/strategy.rb +10 -3
- data/lib/chewy/strategy/active_job.rb +1 -0
- data/lib/chewy/strategy/atomic.rb +1 -3
- data/lib/chewy/strategy/bypass.rb +1 -1
- data/lib/chewy/strategy/resque.rb +1 -0
- data/lib/chewy/strategy/shoryuken.rb +40 -0
- data/lib/chewy/strategy/sidekiq.rb +13 -3
- data/lib/chewy/type.rb +29 -7
- data/lib/chewy/type/actions.rb +26 -2
- data/lib/chewy/type/adapter/active_record.rb +44 -29
- data/lib/chewy/type/adapter/base.rb +27 -7
- data/lib/chewy/type/adapter/mongoid.rb +18 -7
- data/lib/chewy/type/adapter/object.rb +187 -26
- data/lib/chewy/type/adapter/orm.rb +59 -32
- data/lib/chewy/type/adapter/sequel.rb +32 -16
- data/lib/chewy/type/import.rb +145 -191
- data/lib/chewy/type/import/bulk_builder.rb +122 -0
- data/lib/chewy/type/import/bulk_request.rb +76 -0
- data/lib/chewy/type/import/journal_builder.rb +45 -0
- data/lib/chewy/type/import/routine.rb +138 -0
- data/lib/chewy/type/mapping.rb +11 -1
- data/lib/chewy/type/observe.rb +1 -1
- data/lib/chewy/type/syncer.rb +220 -0
- data/lib/chewy/type/witchcraft.rb +27 -13
- data/lib/chewy/type/wrapper.rb +28 -2
- data/lib/chewy/version.rb +1 -1
- data/lib/tasks/chewy.rake +84 -26
- data/spec/chewy/config_spec.rb +82 -1
- data/spec/chewy/fields/base_spec.rb +147 -112
- data/spec/chewy/fields/root_spec.rb +75 -18
- data/spec/chewy/fields/time_fields_spec.rb +2 -3
- data/spec/chewy/index/actions_spec.rb +180 -50
- data/spec/chewy/index/aliases_spec.rb +2 -2
- data/spec/chewy/index/settings_spec.rb +67 -38
- data/spec/chewy/index/specification_spec.rb +160 -0
- data/spec/chewy/index_spec.rb +57 -66
- data/spec/chewy/journal_spec.rb +149 -54
- data/spec/chewy/minitest/helpers_spec.rb +4 -4
- data/spec/chewy/minitest/search_index_receiver_spec.rb +1 -1
- data/spec/chewy/query/criteria_spec.rb +179 -179
- data/spec/chewy/query/filters_spec.rb +15 -15
- data/spec/chewy/query/loading_spec.rb +22 -20
- data/spec/chewy/query/nodes/and_spec.rb +2 -2
- data/spec/chewy/query/nodes/bool_spec.rb +4 -4
- data/spec/chewy/query/nodes/equal_spec.rb +19 -19
- data/spec/chewy/query/nodes/exists_spec.rb +6 -6
- data/spec/chewy/query/nodes/has_child_spec.rb +19 -19
- data/spec/chewy/query/nodes/has_parent_spec.rb +19 -19
- data/spec/chewy/query/nodes/missing_spec.rb +5 -5
- data/spec/chewy/query/nodes/not_spec.rb +3 -2
- data/spec/chewy/query/nodes/or_spec.rb +2 -2
- data/spec/chewy/query/nodes/prefix_spec.rb +5 -5
- data/spec/chewy/query/nodes/query_spec.rb +2 -2
- data/spec/chewy/query/nodes/range_spec.rb +18 -18
- data/spec/chewy/query/nodes/raw_spec.rb +1 -1
- data/spec/chewy/query/nodes/regexp_spec.rb +14 -14
- data/spec/chewy/query/nodes/script_spec.rb +4 -4
- data/spec/chewy/query/pagination/kaminari_spec.rb +3 -55
- data/spec/chewy/query/pagination/will_paginate_spec.rb +5 -0
- data/spec/chewy/query/pagination_spec.rb +25 -21
- data/spec/chewy/query_spec.rb +501 -560
- data/spec/chewy/rake_helper_spec.rb +368 -0
- data/spec/chewy/repository_spec.rb +4 -4
- data/spec/chewy/rspec/update_index_spec.rb +89 -56
- data/spec/chewy/runtime_spec.rb +2 -2
- data/spec/chewy/search/loader_spec.rb +117 -0
- data/spec/chewy/search/pagination/kaminari_examples.rb +71 -0
- data/spec/chewy/search/pagination/kaminari_spec.rb +17 -0
- data/spec/chewy/search/pagination/will_paginate_examples.rb +63 -0
- data/spec/chewy/search/pagination/will_paginate_spec.rb +17 -0
- data/spec/chewy/search/parameters/aggs_spec.rb +5 -0
- data/spec/chewy/search/parameters/bool_storage_examples.rb +53 -0
- data/spec/chewy/search/parameters/docvalue_fields_spec.rb +5 -0
- data/spec/chewy/search/parameters/explain_spec.rb +5 -0
- data/spec/chewy/search/parameters/filter_spec.rb +5 -0
- data/spec/chewy/search/parameters/hash_storage_examples.rb +59 -0
- data/spec/chewy/search/parameters/highlight_spec.rb +5 -0
- data/spec/chewy/search/parameters/indices_boost_spec.rb +83 -0
- data/spec/chewy/search/parameters/integer_storage_examples.rb +32 -0
- data/spec/chewy/search/parameters/limit_spec.rb +5 -0
- data/spec/chewy/search/parameters/load_spec.rb +60 -0
- data/spec/chewy/search/parameters/min_score_spec.rb +32 -0
- data/spec/chewy/search/parameters/none_spec.rb +5 -0
- data/spec/chewy/search/parameters/offset_spec.rb +5 -0
- data/spec/chewy/search/parameters/order_spec.rb +65 -0
- data/spec/chewy/search/parameters/post_filter_spec.rb +5 -0
- data/spec/chewy/search/parameters/preference_spec.rb +5 -0
- data/spec/chewy/search/parameters/profile_spec.rb +5 -0
- data/spec/chewy/search/parameters/query_spec.rb +5 -0
- data/spec/chewy/search/parameters/query_storage_examples.rb +388 -0
- data/spec/chewy/search/parameters/request_cache_spec.rb +67 -0
- data/spec/chewy/search/parameters/rescore_spec.rb +62 -0
- data/spec/chewy/search/parameters/script_fields_spec.rb +5 -0
- data/spec/chewy/search/parameters/search_after_spec.rb +32 -0
- data/spec/chewy/search/parameters/search_type_spec.rb +5 -0
- data/spec/chewy/search/parameters/source_spec.rb +156 -0
- data/spec/chewy/search/parameters/storage_spec.rb +60 -0
- data/spec/chewy/search/parameters/stored_fields_spec.rb +126 -0
- data/spec/chewy/search/parameters/string_array_storage_examples.rb +63 -0
- data/spec/chewy/search/parameters/string_storage_examples.rb +32 -0
- data/spec/chewy/search/parameters/suggest_spec.rb +5 -0
- data/spec/chewy/search/parameters/terminate_after_spec.rb +5 -0
- data/spec/chewy/search/parameters/timeout_spec.rb +5 -0
- data/spec/chewy/search/parameters/track_scores_spec.rb +5 -0
- data/spec/chewy/search/parameters/types_spec.rb +5 -0
- data/spec/chewy/search/parameters/version_spec.rb +5 -0
- data/spec/chewy/search/parameters_spec.rb +130 -0
- data/spec/chewy/search/query_proxy_spec.rb +68 -0
- data/spec/chewy/search/request_spec.rb +669 -0
- data/spec/chewy/search/response_spec.rb +192 -0
- data/spec/chewy/search/scrolling_spec.rb +169 -0
- data/spec/chewy/search_spec.rb +13 -6
- data/spec/chewy/stash_spec.rb +95 -0
- data/spec/chewy/strategy/active_job_spec.rb +6 -0
- data/spec/chewy/strategy/resque_spec.rb +6 -0
- data/spec/chewy/strategy/shoryuken_spec.rb +64 -0
- data/spec/chewy/strategy/sidekiq_spec.rb +8 -0
- data/spec/chewy/strategy_spec.rb +6 -6
- data/spec/chewy/type/actions_spec.rb +29 -10
- data/spec/chewy/type/adapter/active_record_spec.rb +203 -91
- data/spec/chewy/type/adapter/mongoid_spec.rb +112 -54
- data/spec/chewy/type/adapter/object_spec.rb +101 -28
- data/spec/chewy/type/adapter/sequel_spec.rb +149 -82
- data/spec/chewy/type/import/bulk_builder_spec.rb +279 -0
- data/spec/chewy/type/import/bulk_request_spec.rb +102 -0
- data/spec/chewy/type/import/journal_builder_spec.rb +95 -0
- data/spec/chewy/type/import/routine_spec.rb +110 -0
- data/spec/chewy/type/import_spec.rb +350 -271
- data/spec/chewy/type/mapping_spec.rb +54 -18
- data/spec/chewy/type/observe_spec.rb +5 -1
- data/spec/chewy/type/syncer_spec.rb +123 -0
- data/spec/chewy/type/witchcraft_spec.rb +45 -29
- data/spec/chewy/type/wrapper_spec.rb +63 -23
- data/spec/chewy/type_spec.rb +28 -7
- data/spec/chewy_spec.rb +75 -7
- data/spec/spec_helper.rb +5 -2
- data/spec/support/active_record.rb +5 -1
- data/spec/support/class_helpers.rb +0 -14
- data/spec/support/mongoid.rb +15 -3
- data/spec/support/sequel.rb +6 -1
- metadata +198 -37
- data/gemfiles/rails.3.2.activerecord.gemfile +0 -16
- data/gemfiles/rails.3.2.activerecord.kaminari.gemfile +0 -15
- data/gemfiles/rails.3.2.activerecord.will_paginate.gemfile +0 -15
- data/gemfiles/rails.4.2.activerecord.kaminari.gemfile +0 -16
- data/gemfiles/rails.4.2.activerecord.will_paginate.gemfile +0 -16
- data/gemfiles/rails.4.2.mongoid.4.0.gemfile +0 -16
- data/gemfiles/rails.4.2.mongoid.4.0.kaminari.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.4.0.will_paginate.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.5.1.kaminari.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.5.1.will_paginate.gemfile +0 -15
- data/gemfiles/rails.5.0.activerecord.kaminari.gemfile +0 -16
- data/gemfiles/rails.5.0.activerecord.will_paginate.gemfile +0 -16
- data/gemfiles/sequel.4.38.gemfile +0 -14
- data/lib/chewy/journal/apply.rb +0 -31
- data/lib/chewy/journal/clean.rb +0 -24
- data/lib/chewy/journal/entry.rb +0 -83
- data/lib/chewy/journal/query.rb +0 -87
- data/lib/chewy/query/pagination/will_paginate.rb +0 -27
- data/lib/chewy/query/scoping.rb +0 -20
- data/spec/chewy/journal/apply_spec.rb +0 -120
- data/spec/chewy/journal/entry_spec.rb +0 -237
- data/spec/chewy/query/pagination/will_paginage_spec.rb +0 -59
@@ -1,9 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Chewy::Fields::Root do
|
4
|
-
specify { expect(described_class.new('name').value).to be_a(Proc) }
|
5
|
-
# TODO: add 'should_behave_like base_field'
|
6
|
-
|
7
4
|
subject(:field) { described_class.new('product') }
|
8
5
|
|
9
6
|
describe '#dynamic_template' do
|
@@ -13,34 +10,94 @@ describe Chewy::Fields::Root do
|
|
13
10
|
field.dynamic_template 'hello.*'
|
14
11
|
field.dynamic_template(/hello/)
|
15
12
|
field.dynamic_template(/hello.*/)
|
16
|
-
field.dynamic_template template_42: {
|
13
|
+
field.dynamic_template template_42: {mapping: {}, match: ''}
|
17
14
|
field.dynamic_template(/hello\..*/)
|
18
15
|
|
19
|
-
expect(field.mappings_hash).to eq(product: {
|
20
|
-
{
|
21
|
-
{
|
22
|
-
{
|
23
|
-
{
|
24
|
-
{
|
25
|
-
{
|
26
|
-
{
|
27
|
-
]
|
16
|
+
expect(field.mappings_hash).to eq(product: {dynamic_templates: [
|
17
|
+
{template_1: {mapping: {type: 'string'}, match: 'hello'}},
|
18
|
+
{template_2: {mapping: {}, match_mapping_type: 'integer', match: 'hello*'}},
|
19
|
+
{template_3: {mapping: {}, path_match: 'hello.*'}},
|
20
|
+
{template_4: {mapping: {}, match: 'hello', match_pattern: 'regexp'}},
|
21
|
+
{template_5: {mapping: {}, match: 'hello.*', match_pattern: 'regexp'}},
|
22
|
+
{template_42: {mapping: {}, match: ''}},
|
23
|
+
{template_7: {mapping: {}, path_match: 'hello\..*', match_pattern: 'regexp'}}
|
24
|
+
]})
|
28
25
|
end
|
29
26
|
|
30
27
|
context do
|
31
28
|
subject(:field) do
|
32
29
|
described_class.new('product', dynamic_templates: [
|
33
|
-
{
|
30
|
+
{template_42: {mapping: {}, match: ''}}
|
34
31
|
])
|
35
32
|
end
|
36
33
|
|
37
34
|
specify do
|
38
35
|
field.dynamic_template 'hello', type: 'string'
|
39
|
-
expect(field.mappings_hash).to eq(product: {
|
40
|
-
{
|
41
|
-
{
|
42
|
-
]
|
36
|
+
expect(field.mappings_hash).to eq(product: {dynamic_templates: [
|
37
|
+
{template_42: {mapping: {}, match: ''}},
|
38
|
+
{template_1: {mapping: {type: 'string'}, match: 'hello'}}
|
39
|
+
]})
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#compose' do
|
45
|
+
context 'empty children', :orm do
|
46
|
+
before do
|
47
|
+
stub_model(:city)
|
48
|
+
stub_index(:places) do
|
49
|
+
define_type City
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
let(:city) { City.new(name: 'London', rating: 100) }
|
54
|
+
|
55
|
+
specify do
|
56
|
+
expect(PlacesIndex::City.send(:build_root).compose(city))
|
57
|
+
.to match(hash_including('name' => 'London', 'rating' => 100))
|
58
|
+
end
|
59
|
+
specify do
|
60
|
+
expect(PlacesIndex::City.send(:build_root).compose(city, fields: %i[name borogoves]))
|
61
|
+
.to eq('name' => 'London')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'has children' do
|
66
|
+
before do
|
67
|
+
stub_index(:places) do
|
68
|
+
define_type :city do
|
69
|
+
field :name, :rating
|
70
|
+
end
|
71
|
+
end
|
43
72
|
end
|
73
|
+
|
74
|
+
let(:city) { double(name: 'London', rating: 100) }
|
75
|
+
|
76
|
+
specify do
|
77
|
+
expect(PlacesIndex::City.send(:build_root).compose(city))
|
78
|
+
.to eq('name' => 'London', 'rating' => 100)
|
79
|
+
end
|
80
|
+
specify do
|
81
|
+
expect(PlacesIndex::City.send(:build_root).compose(city, fields: %i[name borogoves]))
|
82
|
+
.to eq('name' => 'London')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#child_hash' do
|
88
|
+
before do
|
89
|
+
stub_index(:places) do
|
90
|
+
define_type :city do
|
91
|
+
field :name, :rating
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
specify do
|
97
|
+
expect(PlacesIndex::City.send(:build_root).child_hash).to match(
|
98
|
+
name: an_instance_of(Chewy::Fields::Base).and(have_attributes(name: :name)),
|
99
|
+
rating: an_instance_of(Chewy::Fields::Base).and(have_attributes(name: :rating))
|
100
|
+
)
|
44
101
|
end
|
45
102
|
end
|
46
103
|
end
|
@@ -23,7 +23,6 @@ describe 'Time fields' do
|
|
23
23
|
let(:range) { (time - 1.minute)..(time + 1.minute) }
|
24
24
|
|
25
25
|
specify { expect(PostsIndex.total).to eq(3) }
|
26
|
-
specify { expect(PostsIndex.filter {
|
27
|
-
specify { expect(PostsIndex.filter {
|
28
|
-
specify { expect(PostsIndex.filter { published_at == o { [range.min..range.max] } }.count).to eq(1) }
|
26
|
+
specify { expect(PostsIndex.filter(range: {published_at: {gte: range.min, lte: range.max}}).size).to eq(1) }
|
27
|
+
specify { expect(PostsIndex.filter(range: {published_at: {gt: range.min.utc, lt: (range.max + 1.hour).utc}}).size).to eq(2) }
|
29
28
|
end
|
@@ -35,7 +35,7 @@ describe Chewy::Index::Actions do
|
|
35
35
|
|
36
36
|
context do
|
37
37
|
before { DummiesIndex.create '2014' }
|
38
|
-
specify { expect(DummiesIndex.indexes).to match_array(%w
|
38
|
+
specify { expect(DummiesIndex.indexes).to match_array(%w[dummies_2013 dummies_2014]) }
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -55,11 +55,6 @@ describe Chewy::Index::Actions do
|
|
55
55
|
context do
|
56
56
|
before { DummiesIndex.create }
|
57
57
|
specify do
|
58
|
-
skip_on_version_gte('2.0', 'format of exception changed in 2.x')
|
59
|
-
expect { DummiesIndex.create! }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/\[\[dummies\] already exists\]/)
|
60
|
-
end
|
61
|
-
specify do
|
62
|
-
skip_on_version_lt('2.0', 'format of exception was changed')
|
63
58
|
expect { DummiesIndex.create! }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/index_already_exists_exception.*dummies/)
|
64
59
|
end
|
65
60
|
specify { expect { DummiesIndex.create!('2013') }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/Invalid alias name \[dummies\]/) }
|
@@ -72,18 +67,13 @@ describe Chewy::Index::Actions do
|
|
72
67
|
specify { expect(DummiesIndex.aliases).to eq([]) }
|
73
68
|
specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
|
74
69
|
specify do
|
75
|
-
skip_on_version_gte('2.0', 'format of exception changed in 2.x')
|
76
|
-
expect { DummiesIndex.create!('2013') }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/\[\[dummies_2013\] already exists\]/)
|
77
|
-
end
|
78
|
-
specify do
|
79
|
-
skip_on_version_lt('2.0', 'format of exception was changed')
|
80
70
|
expect { DummiesIndex.create!('2013') }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/index_already_exists_exception.*dummies_2013/)
|
81
71
|
end
|
82
72
|
specify { expect(DummiesIndex.create!('2014')['acknowledged']).to eq(true) }
|
83
73
|
|
84
74
|
context do
|
85
75
|
before { DummiesIndex.create! '2014' }
|
86
|
-
specify { expect(DummiesIndex.indexes).to match_array(%w
|
76
|
+
specify { expect(DummiesIndex.indexes).to match_array(%w[dummies_2013 dummies_2014]) }
|
87
77
|
end
|
88
78
|
end
|
89
79
|
|
@@ -336,82 +326,222 @@ describe Chewy::Index::Actions do
|
|
336
326
|
end
|
337
327
|
end
|
338
328
|
|
339
|
-
before { City.create!(id: 1, name: 'Moscow') }
|
340
|
-
|
341
|
-
specify { expect(CitiesIndex.reset!).to eq(true) }
|
342
|
-
specify { expect(CitiesIndex.reset!('2013')).to eq(true) }
|
343
|
-
|
344
329
|
context do
|
345
|
-
before {
|
330
|
+
before { City.create!(id: 1, name: 'Moscow') }
|
346
331
|
|
347
|
-
specify { expect(CitiesIndex.
|
348
|
-
specify { expect(CitiesIndex.
|
349
|
-
specify { expect(CitiesIndex.indexes).to eq([]) }
|
332
|
+
specify { expect(CitiesIndex.reset!).to eq(true) }
|
333
|
+
specify { expect(CitiesIndex.reset!('2013')).to eq(true) }
|
350
334
|
|
351
335
|
context do
|
352
|
-
before { CitiesIndex.reset!
|
336
|
+
before { CitiesIndex.reset! }
|
353
337
|
|
354
338
|
specify { expect(CitiesIndex.all).to have(1).item }
|
355
339
|
specify { expect(CitiesIndex.aliases).to eq([]) }
|
356
|
-
specify { expect(CitiesIndex.indexes).to eq([
|
340
|
+
specify { expect(CitiesIndex.indexes).to eq([]) }
|
341
|
+
|
342
|
+
context do
|
343
|
+
before { CitiesIndex.reset!('2013') }
|
344
|
+
|
345
|
+
specify { expect(CitiesIndex.all).to have(1).item }
|
346
|
+
specify { expect(CitiesIndex.aliases).to eq([]) }
|
347
|
+
specify { expect(CitiesIndex.indexes).to eq(['cities_2013']) }
|
348
|
+
end
|
349
|
+
|
350
|
+
context do
|
351
|
+
before { CitiesIndex.reset! }
|
352
|
+
|
353
|
+
specify { expect(CitiesIndex.all).to have(1).item }
|
354
|
+
specify { expect(CitiesIndex.aliases).to eq([]) }
|
355
|
+
specify { expect(CitiesIndex.indexes).to eq([]) }
|
356
|
+
end
|
357
357
|
end
|
358
358
|
|
359
359
|
context do
|
360
|
-
before { CitiesIndex.reset! }
|
360
|
+
before { CitiesIndex.reset!('2013') }
|
361
361
|
|
362
362
|
specify { expect(CitiesIndex.all).to have(1).item }
|
363
363
|
specify { expect(CitiesIndex.aliases).to eq([]) }
|
364
|
-
specify { expect(CitiesIndex.indexes).to eq([]) }
|
364
|
+
specify { expect(CitiesIndex.indexes).to eq(['cities_2013']) }
|
365
|
+
|
366
|
+
context do
|
367
|
+
before { CitiesIndex.reset!('2014') }
|
368
|
+
|
369
|
+
specify { expect(CitiesIndex.all).to have(1).item }
|
370
|
+
specify { expect(CitiesIndex.aliases).to eq([]) }
|
371
|
+
specify { expect(CitiesIndex.indexes).to eq(['cities_2014']) }
|
372
|
+
specify { expect(Chewy.client.indices.exists(index: 'cities_2013')).to eq(false) }
|
373
|
+
end
|
374
|
+
|
375
|
+
context do
|
376
|
+
before { CitiesIndex.reset! }
|
377
|
+
|
378
|
+
specify { expect(CitiesIndex.all).to have(1).item }
|
379
|
+
specify { expect(CitiesIndex.aliases).to eq([]) }
|
380
|
+
specify { expect(CitiesIndex.indexes).to eq([]) }
|
381
|
+
specify { expect(Chewy.client.indices.exists(index: 'cities_2013')).to eq(false) }
|
382
|
+
end
|
365
383
|
end
|
366
384
|
end
|
367
385
|
|
368
|
-
context do
|
386
|
+
context 'reset_disable_refresh_interval' do
|
387
|
+
let(:suffix) { Time.now.to_i }
|
388
|
+
let(:name) { CitiesIndex.index_name(suffix: suffix) }
|
389
|
+
let(:before_import_body) do
|
390
|
+
{
|
391
|
+
index: {refresh_interval: -1}
|
392
|
+
}
|
393
|
+
end
|
394
|
+
let(:after_import_body) do
|
395
|
+
{
|
396
|
+
index: {refresh_interval: '1s'}
|
397
|
+
}
|
398
|
+
end
|
399
|
+
|
369
400
|
before { CitiesIndex.reset!('2013') }
|
401
|
+
before { allow(Chewy).to receive(:reset_disable_refresh_interval).and_return(reset_disable_refresh_interval) }
|
402
|
+
|
403
|
+
context 'activated' do
|
404
|
+
let(:reset_disable_refresh_interval) { true }
|
405
|
+
specify do
|
406
|
+
expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: before_import_body).once
|
407
|
+
expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: after_import_body).once
|
408
|
+
expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: false).and_call_original
|
409
|
+
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
410
|
+
end
|
370
411
|
|
371
|
-
|
372
|
-
|
373
|
-
|
412
|
+
context 'refresh_interval already defined' do
|
413
|
+
before do
|
414
|
+
stub_index(:cities) do
|
415
|
+
settings index: {refresh_interval: '2s'}
|
416
|
+
define_type City
|
417
|
+
end
|
418
|
+
end
|
374
419
|
|
375
|
-
|
376
|
-
|
420
|
+
let(:after_import_body) do
|
421
|
+
{
|
422
|
+
index: {refresh_interval: '2s'}
|
423
|
+
}
|
424
|
+
end
|
377
425
|
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
426
|
+
specify do
|
427
|
+
expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: before_import_body).once
|
428
|
+
expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: after_import_body).once
|
429
|
+
expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: false).and_call_original
|
430
|
+
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
431
|
+
end
|
432
|
+
end
|
382
433
|
end
|
383
434
|
|
384
|
-
context do
|
385
|
-
|
435
|
+
context 'not activated' do
|
436
|
+
let(:reset_disable_refresh_interval) { false }
|
437
|
+
specify do
|
438
|
+
expect(CitiesIndex.client.indices).not_to receive(:put_settings)
|
439
|
+
expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: true).and_call_original
|
440
|
+
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
441
|
+
end
|
442
|
+
end
|
443
|
+
end
|
386
444
|
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
445
|
+
context 'reset_no_replicas' do
|
446
|
+
let(:suffix) { Time.now.to_i }
|
447
|
+
let(:name) { CitiesIndex.index_name(suffix: suffix) }
|
448
|
+
let(:before_import_body) do
|
449
|
+
{
|
450
|
+
index: {number_of_replicas: 0}
|
451
|
+
}
|
452
|
+
end
|
453
|
+
let(:after_import_body) do
|
454
|
+
{
|
455
|
+
index: {number_of_replicas: 0}
|
456
|
+
}
|
457
|
+
end
|
458
|
+
|
459
|
+
before { allow(Chewy).to receive(:reset_no_replicas).and_return(reset_no_replicas) }
|
460
|
+
|
461
|
+
context 'activated' do
|
462
|
+
let(:reset_no_replicas) { true }
|
463
|
+
specify do
|
464
|
+
expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: before_import_body).once
|
465
|
+
expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: after_import_body).once
|
466
|
+
expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: true).and_call_original
|
467
|
+
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
468
|
+
end
|
469
|
+
end
|
470
|
+
|
471
|
+
context 'not activated' do
|
472
|
+
let(:reset_no_replicas) { false }
|
473
|
+
specify do
|
474
|
+
expect(CitiesIndex.client.indices).not_to receive(:put_settings)
|
475
|
+
expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: true).and_call_original
|
476
|
+
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
477
|
+
end
|
391
478
|
end
|
392
479
|
end
|
393
480
|
|
394
|
-
context '
|
481
|
+
context 'applying journal' do
|
395
482
|
before do
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
483
|
+
stub_index(:cities) do
|
484
|
+
define_type City do
|
485
|
+
field :name, value: (lambda do
|
486
|
+
sleep(rating)
|
487
|
+
name
|
488
|
+
end)
|
489
|
+
end
|
400
490
|
end
|
401
491
|
end
|
402
492
|
|
493
|
+
let!(:cities) { Array.new(3) { |i| City.create!(id: i + 1, name: "Name#{i + 1}", rating: 1) } }
|
494
|
+
|
495
|
+
let(:parallel_update) do
|
496
|
+
Thread.new do
|
497
|
+
sleep(1.5)
|
498
|
+
cities.first.update(name: 'NewName1', rating: 0)
|
499
|
+
cities.last.update(name: 'NewName3', rating: 0)
|
500
|
+
CitiesIndex::City.import!([cities.first, cities.last], journal: true)
|
501
|
+
end
|
502
|
+
end
|
503
|
+
|
504
|
+
specify 'with journal application' do
|
505
|
+
parallel_update
|
506
|
+
CitiesIndex.reset!('suffix')
|
507
|
+
expect(CitiesIndex::City.pluck(:_id, :name)).to contain_exactly(%w[1 NewName1], %w[2 Name2], %w[3 NewName3])
|
508
|
+
end
|
509
|
+
|
510
|
+
specify 'without journal application' do
|
511
|
+
parallel_update
|
512
|
+
CitiesIndex.reset!('suffix', apply_journal: false)
|
513
|
+
expect(CitiesIndex::City.pluck(:_id, :name)).to contain_exactly(%w[1 Name1], %w[2 Name2], %w[3 Name3])
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
517
|
+
context 'journaling' do
|
518
|
+
before { City.create!(id: 1, name: 'Moscow') }
|
519
|
+
|
403
520
|
specify do
|
404
521
|
CitiesIndex.reset!
|
405
|
-
|
406
|
-
expect(Chewy.client.indices.exists?(index: Chewy::Journal.index_name)).to eq false
|
522
|
+
expect(Chewy::Stash::Journal.count).to eq(0)
|
407
523
|
end
|
408
524
|
|
409
525
|
specify do
|
410
526
|
CitiesIndex.reset! journal: true
|
527
|
+
expect(Chewy::Stash::Journal.count).to be > 0
|
528
|
+
end
|
529
|
+
end
|
411
530
|
|
412
|
-
|
413
|
-
|
531
|
+
context 'other options' do
|
532
|
+
specify do
|
533
|
+
expect(CitiesIndex::City).to receive(:import).with(parallel: true, journal: false).once.and_return(true)
|
534
|
+
expect(CitiesIndex.reset!(parallel: true)).to eq(true)
|
535
|
+
end
|
536
|
+
|
537
|
+
specify do
|
538
|
+
expect(CitiesIndex::City).to receive(:import).with(suffix: 'suffix', parallel: true, journal: false, refresh: true).once.and_return(true)
|
539
|
+
expect(CitiesIndex.reset!('suffix', parallel: true)).to eq(true)
|
414
540
|
end
|
415
541
|
end
|
416
542
|
end
|
543
|
+
|
544
|
+
describe '.journal' do
|
545
|
+
specify { expect(DummiesIndex.journal).to be_a(Chewy::Journal) }
|
546
|
+
end
|
417
547
|
end
|
@@ -22,7 +22,7 @@ describe Chewy::Index::Aliases do
|
|
22
22
|
context do
|
23
23
|
before { DummiesIndex.create! '2013' }
|
24
24
|
before { DummiesIndex.create! '2014' }
|
25
|
-
specify { expect(DummiesIndex.indexes).to match_array(%w
|
25
|
+
specify { expect(DummiesIndex.indexes).to match_array(%w[dummies_2013 dummies_2014]) }
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -38,7 +38,7 @@ describe Chewy::Index::Aliases do
|
|
38
38
|
before { DummiesIndex.create! }
|
39
39
|
before { Chewy.client.indices.put_alias index: 'dummies', name: 'dummies_2013' }
|
40
40
|
before { Chewy.client.indices.put_alias index: 'dummies', name: 'dummies_2014' }
|
41
|
-
specify { expect(DummiesIndex.aliases).to match_array(%w
|
41
|
+
specify { expect(DummiesIndex.aliases).to match_array(%w[dummies_2013 dummies_2014]) }
|
42
42
|
end
|
43
43
|
|
44
44
|
context do
|
@@ -6,30 +6,59 @@ describe Chewy::Index::Settings do
|
|
6
6
|
before { allow(Chewy).to receive_messages(repository: Chewy::Repository.send(:new)) }
|
7
7
|
|
8
8
|
specify { expect(described_class.new.to_hash).to eq({}) }
|
9
|
-
specify { expect(described_class.new(number_of_nodes: 3).to_hash).to eq(settings: {
|
9
|
+
specify { expect(described_class.new(number_of_nodes: 3).to_hash).to eq(settings: {number_of_nodes: 3}) }
|
10
10
|
specify do
|
11
11
|
expect(described_class.new(number_of_nodes: 3, analysis: {}).to_hash)
|
12
|
-
.to eq(settings: {
|
12
|
+
.to eq(settings: {number_of_nodes: 3, analysis: {}})
|
13
13
|
end
|
14
14
|
specify do
|
15
|
-
expect(described_class.new(number_of_nodes: 3, analysis: {
|
16
|
-
.to eq(settings: {
|
15
|
+
expect(described_class.new(number_of_nodes: 3, analysis: {filter: {filter1: {}}}).to_hash)
|
16
|
+
.to eq(settings: {number_of_nodes: 3, analysis: {filter: {filter1: {}}}})
|
17
17
|
end
|
18
18
|
specify do
|
19
|
-
expect(described_class.new(number_of_nodes: 3, analysis: {
|
20
|
-
.to eq(settings: {
|
19
|
+
expect(described_class.new(number_of_nodes: 3, analysis: {analyzer: {analyzer1: {}}}).to_hash)
|
20
|
+
.to eq(settings: {number_of_nodes: 3, analysis: {analyzer: {analyzer1: {}}}})
|
21
21
|
end
|
22
22
|
specify do
|
23
23
|
expect(described_class.new(number_of_nodes: 3, analysis: {
|
24
|
-
|
25
|
-
|
26
|
-
.to eq(settings: {
|
27
|
-
|
28
|
-
|
24
|
+
analyzer: {analyzer1: {tokenizer: 'tokenizer1', filter: %w[filter1 filter2]}}
|
25
|
+
}).to_hash)
|
26
|
+
.to eq(settings: {number_of_nodes: 3, analysis: {
|
27
|
+
analyzer: {analyzer1: {tokenizer: 'tokenizer1', filter: %w[filter1 filter2]}}
|
28
|
+
}})
|
29
29
|
end
|
30
30
|
specify do
|
31
|
-
expect(described_class.new(number_of_nodes: 3, analysis: {
|
32
|
-
.to eq(settings: {
|
31
|
+
expect(described_class.new(number_of_nodes: 3, analysis: {analyzer: ['analyzer1']}).to_hash)
|
32
|
+
.to eq(settings: {number_of_nodes: 3, analysis: {}})
|
33
|
+
end
|
34
|
+
specify do
|
35
|
+
expect(described_class.new(number_of_nodes: 3, analysis: {analyzer: {analyzer1: {}}, normalizer: {}}).to_hash)
|
36
|
+
.to eq(settings: {number_of_nodes: 3, analysis: {analyzer: {analyzer1: {}}, normalizer: {}}})
|
37
|
+
end
|
38
|
+
specify do
|
39
|
+
expect(described_class.new(number_of_nodes: 3, analysis: {analyzer: ['analyzer1'], normalizer: {}}).to_hash)
|
40
|
+
.to eq(settings: {number_of_nodes: 3, analysis: {normalizer: {}}})
|
41
|
+
end
|
42
|
+
|
43
|
+
specify do
|
44
|
+
stub_const('Synonyms', Class.new do
|
45
|
+
def self.synonyms
|
46
|
+
['kaftan => dress']
|
47
|
+
end
|
48
|
+
end)
|
49
|
+
expect(
|
50
|
+
described_class.new do
|
51
|
+
{
|
52
|
+
analysis: {filter: {synonym: {type: 'synonym', synonyms: Synonyms.synonyms}}}
|
53
|
+
}
|
54
|
+
end.to_hash
|
55
|
+
).to eq(settings: {
|
56
|
+
analysis: {filter: {
|
57
|
+
synonym: {
|
58
|
+
type: 'synonym', synonyms: ['kaftan => dress']
|
59
|
+
}
|
60
|
+
}}
|
61
|
+
})
|
33
62
|
end
|
34
63
|
|
35
64
|
context do
|
@@ -37,12 +66,12 @@ describe Chewy::Index::Settings do
|
|
37
66
|
|
38
67
|
specify do
|
39
68
|
expect(described_class.new(number_of_nodes: 3, analysis: {
|
40
|
-
|
41
|
-
|
42
|
-
.to eq(settings: {
|
43
|
-
|
44
|
-
|
45
|
-
|
69
|
+
analyzer: {analyzer1: {tokenizer: 'tokenizer1', filter: %w[filter1 filter2]}}
|
70
|
+
}).to_hash)
|
71
|
+
.to eq(settings: {number_of_nodes: 3, analysis: {
|
72
|
+
analyzer: {analyzer1: {tokenizer: 'tokenizer1', filter: %w[filter1 filter2]}},
|
73
|
+
tokenizer: {tokenizer1: {options: 42}}
|
74
|
+
}})
|
46
75
|
end
|
47
76
|
end
|
48
77
|
|
@@ -55,13 +84,13 @@ describe Chewy::Index::Settings do
|
|
55
84
|
|
56
85
|
specify do
|
57
86
|
expect(described_class.new(number_of_nodes: 3, analysis: {
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
.to eq(settings: {
|
62
|
-
|
63
|
-
|
64
|
-
|
87
|
+
analyzer: {analyzer1: {tokenizer: 'tokenizer1', filter: %w[filter1 filter2]}},
|
88
|
+
filter: ['filter3', {filter4: {options: 45}}]
|
89
|
+
}).to_hash)
|
90
|
+
.to eq(settings: {number_of_nodes: 3, analysis: {
|
91
|
+
analyzer: {analyzer1: {tokenizer: 'tokenizer1', filter: %w[filter1 filter2]}},
|
92
|
+
filter: {filter2: {options: 42}, filter3: {options: 43}, filter4: {options: 45}}
|
93
|
+
}})
|
65
94
|
end
|
66
95
|
end
|
67
96
|
|
@@ -73,31 +102,31 @@ describe Chewy::Index::Settings do
|
|
73
102
|
|
74
103
|
specify do
|
75
104
|
expect(described_class.new(number_of_nodes: 3, analysis: {
|
76
|
-
|
77
|
-
|
78
|
-
.to eq(settings: {
|
79
|
-
|
80
|
-
|
81
|
-
|
105
|
+
analyzer: ['analyzer1', {analyzer2: {options: 44}}]
|
106
|
+
}).to_hash)
|
107
|
+
.to eq(settings: {number_of_nodes: 3, analysis: {
|
108
|
+
analyzer: {analyzer1: {options: 42, tokenizer: 'tokenizer1'}, analyzer2: {options: 44}},
|
109
|
+
tokenizer: {tokenizer1: {options: 43}}
|
110
|
+
}})
|
82
111
|
end
|
83
112
|
end
|
84
113
|
|
85
114
|
context ':index' do
|
86
115
|
specify do
|
87
|
-
expect(described_class.new(index: {
|
88
|
-
.to eq(settings: {
|
116
|
+
expect(described_class.new(index: {number_of_shards: 3}).to_hash)
|
117
|
+
.to eq(settings: {index: {number_of_shards: 3}})
|
89
118
|
end
|
90
119
|
|
91
120
|
context do
|
92
|
-
before { allow(Chewy).to receive_messages(configuration: {
|
121
|
+
before { allow(Chewy).to receive_messages(configuration: {index: {number_of_shards: 7, number_of_replicas: 2}}) }
|
93
122
|
|
94
123
|
specify do
|
95
124
|
expect(described_class.new.to_hash)
|
96
|
-
.to eq(settings: {
|
125
|
+
.to eq(settings: {index: {number_of_shards: 7, number_of_replicas: 2}})
|
97
126
|
end
|
98
127
|
specify do
|
99
|
-
expect(described_class.new(index: {
|
100
|
-
.to eq(settings: {
|
128
|
+
expect(described_class.new(index: {number_of_shards: 3}).to_hash)
|
129
|
+
.to eq(settings: {index: {number_of_shards: 3, number_of_replicas: 2}})
|
101
130
|
end
|
102
131
|
end
|
103
132
|
end
|