chewy 0.10.1 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +240 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +16 -0
- data/.rubocop.yml +25 -25
- data/Appraisals +12 -10
- data/CHANGELOG.md +312 -331
- data/CODE_OF_CONDUCT.md +14 -0
- data/CONTRIBUTING.md +63 -0
- data/Gemfile +5 -1
- data/LICENSE.txt +1 -1
- data/README.md +143 -77
- data/chewy.gemspec +10 -12
- data/gemfiles/{rails.4.2.mongoid.5.1.gemfile → rails.5.2.activerecord.gemfile} +6 -4
- data/gemfiles/{rails.4.2.activerecord.gemfile → rails.5.2.mongoid.6.4.gemfile} +6 -4
- data/gemfiles/{rails.4.0.activerecord.gemfile → rails.6.0.activerecord.gemfile} +6 -3
- data/gemfiles/rails.6.1.activerecord.gemfile +19 -0
- data/gemfiles/sequel.4.45.gemfile +2 -2
- data/lib/chewy.rb +2 -1
- data/lib/chewy/backports/duplicable.rb +1 -1
- data/lib/chewy/config.rb +10 -39
- data/lib/chewy/fields/base.rb +9 -3
- data/lib/chewy/fields/root.rb +13 -9
- data/lib/chewy/index.rb +3 -1
- data/lib/chewy/index/actions.rb +28 -16
- data/lib/chewy/index/aliases.rb +16 -5
- data/lib/chewy/index/settings.rb +2 -0
- data/lib/chewy/index/specification.rb +12 -10
- data/lib/chewy/minitest/helpers.rb +6 -6
- data/lib/chewy/minitest/search_index_receiver.rb +17 -17
- data/lib/chewy/multi_search.rb +62 -0
- data/lib/chewy/railtie.rb +3 -5
- data/lib/chewy/rake_helper.rb +5 -5
- data/lib/chewy/rspec/update_index.rb +3 -5
- data/lib/chewy/search.rb +4 -11
- data/lib/chewy/search/loader.rb +1 -1
- data/lib/chewy/search/pagination/will_paginate.rb +1 -1
- data/lib/chewy/search/parameters.rb +24 -6
- data/lib/chewy/search/parameters/allow_partial_search_results.rb +27 -0
- data/lib/chewy/search/parameters/concerns/query_storage.rb +4 -3
- data/lib/chewy/search/parameters/indices.rb +123 -0
- data/lib/chewy/search/parameters/none.rb +1 -3
- data/lib/chewy/search/request.rb +101 -74
- data/lib/chewy/search/scrolling.rb +7 -6
- data/lib/chewy/stash.rb +31 -22
- data/lib/chewy/strategy/active_job.rb +1 -1
- data/lib/chewy/strategy/atomic.rb +1 -1
- data/lib/chewy/strategy/sidekiq.rb +1 -1
- data/lib/chewy/type.rb +5 -2
- data/lib/chewy/type/adapter/active_record.rb +1 -1
- data/lib/chewy/type/adapter/base.rb +9 -9
- data/lib/chewy/type/adapter/mongoid.rb +2 -4
- data/lib/chewy/type/adapter/orm.rb +7 -4
- data/lib/chewy/type/adapter/sequel.rb +5 -7
- data/lib/chewy/type/crutch.rb +1 -1
- data/lib/chewy/type/import.rb +16 -5
- data/lib/chewy/type/import/bulk_builder.rb +1 -1
- data/lib/chewy/type/import/bulk_request.rb +4 -2
- data/lib/chewy/type/import/journal_builder.rb +3 -3
- data/lib/chewy/type/import/routine.rb +3 -3
- data/lib/chewy/type/mapping.rb +42 -36
- data/lib/chewy/type/observe.rb +16 -12
- data/lib/chewy/type/syncer.rb +6 -7
- data/lib/chewy/type/witchcraft.rb +5 -3
- data/lib/chewy/type/wrapper.rb +14 -4
- data/lib/chewy/version.rb +1 -1
- data/lib/sequel/plugins/chewy_observe.rb +4 -19
- data/migration_guide.md +34 -0
- data/spec/chewy/config_spec.rb +16 -21
- data/spec/chewy/fields/base_spec.rb +68 -70
- data/spec/chewy/fields/root_spec.rb +13 -13
- data/spec/chewy/index/actions_spec.rb +157 -38
- data/spec/chewy/index/aliases_spec.rb +3 -3
- data/spec/chewy/index/specification_spec.rb +25 -16
- data/spec/chewy/index_spec.rb +75 -45
- data/spec/chewy/journal_spec.rb +33 -29
- data/spec/chewy/minitest/search_index_receiver_spec.rb +11 -9
- data/spec/chewy/multi_search_spec.rb +85 -0
- data/spec/chewy/rake_helper_spec.rb +123 -95
- data/spec/chewy/rspec/update_index_spec.rb +47 -46
- data/spec/chewy/runtime_spec.rb +2 -2
- data/spec/chewy/search/parameters/indices_spec.rb +190 -0
- data/spec/chewy/search/parameters/none_spec.rb +1 -1
- data/spec/chewy/search/parameters_spec.rb +21 -4
- data/spec/chewy/search/request_spec.rb +103 -70
- data/spec/chewy/search/response_spec.rb +27 -17
- data/spec/chewy/search/scrolling_spec.rb +27 -17
- data/spec/chewy/search_spec.rb +49 -35
- data/spec/chewy/stash_spec.rb +15 -13
- data/spec/chewy/strategy/active_job_spec.rb +15 -2
- data/spec/chewy/strategy/shoryuken_spec.rb +8 -2
- data/spec/chewy/strategy/sidekiq_spec.rb +6 -2
- data/spec/chewy/type/adapter/active_record_spec.rb +16 -4
- data/spec/chewy/type/import/bulk_builder_spec.rb +9 -94
- data/spec/chewy/type/import/journal_builder_spec.rb +17 -15
- data/spec/chewy/type/import_spec.rb +15 -0
- data/spec/chewy/type/mapping_spec.rb +51 -18
- data/spec/chewy/type/observe_spec.rb +4 -4
- data/spec/chewy/type/witchcraft_spec.rb +15 -0
- data/spec/chewy/type/wrapper_spec.rb +3 -1
- data/spec/chewy_spec.rb +0 -7
- data/spec/spec_helper.rb +5 -1
- data/spec/support/active_record.rb +21 -0
- metadata +51 -116
- data/.travis.yml +0 -53
- data/LEGACY_DSL.md +0 -497
- data/gemfiles/rails.4.1.activerecord.gemfile +0 -14
- data/gemfiles/rails.5.0.activerecord.gemfile +0 -15
- data/gemfiles/rails.5.0.mongoid.6.0.gemfile +0 -15
- data/gemfiles/rails.5.1.activerecord.gemfile +0 -15
- data/gemfiles/rails.5.1.mongoid.6.1.gemfile +0 -15
- data/lib/chewy/query.rb +0 -1098
- data/lib/chewy/query/compose.rb +0 -68
- data/lib/chewy/query/criteria.rb +0 -191
- data/lib/chewy/query/filters.rb +0 -227
- data/lib/chewy/query/loading.rb +0 -111
- data/lib/chewy/query/nodes/and.rb +0 -25
- data/lib/chewy/query/nodes/base.rb +0 -17
- data/lib/chewy/query/nodes/bool.rb +0 -34
- data/lib/chewy/query/nodes/equal.rb +0 -34
- data/lib/chewy/query/nodes/exists.rb +0 -20
- data/lib/chewy/query/nodes/expr.rb +0 -28
- data/lib/chewy/query/nodes/field.rb +0 -110
- data/lib/chewy/query/nodes/has_child.rb +0 -15
- data/lib/chewy/query/nodes/has_parent.rb +0 -15
- data/lib/chewy/query/nodes/has_relation.rb +0 -59
- data/lib/chewy/query/nodes/match_all.rb +0 -11
- data/lib/chewy/query/nodes/missing.rb +0 -20
- data/lib/chewy/query/nodes/not.rb +0 -25
- data/lib/chewy/query/nodes/or.rb +0 -25
- data/lib/chewy/query/nodes/prefix.rb +0 -19
- data/lib/chewy/query/nodes/query.rb +0 -20
- data/lib/chewy/query/nodes/range.rb +0 -63
- data/lib/chewy/query/nodes/raw.rb +0 -15
- data/lib/chewy/query/nodes/regexp.rb +0 -35
- data/lib/chewy/query/nodes/script.rb +0 -20
- data/lib/chewy/query/pagination.rb +0 -25
- data/spec/chewy/query/criteria_spec.rb +0 -700
- data/spec/chewy/query/filters_spec.rb +0 -201
- data/spec/chewy/query/loading_spec.rb +0 -124
- data/spec/chewy/query/nodes/and_spec.rb +0 -12
- data/spec/chewy/query/nodes/bool_spec.rb +0 -14
- data/spec/chewy/query/nodes/equal_spec.rb +0 -32
- data/spec/chewy/query/nodes/exists_spec.rb +0 -18
- data/spec/chewy/query/nodes/has_child_spec.rb +0 -59
- data/spec/chewy/query/nodes/has_parent_spec.rb +0 -59
- data/spec/chewy/query/nodes/match_all_spec.rb +0 -11
- data/spec/chewy/query/nodes/missing_spec.rb +0 -16
- data/spec/chewy/query/nodes/not_spec.rb +0 -13
- data/spec/chewy/query/nodes/or_spec.rb +0 -12
- data/spec/chewy/query/nodes/prefix_spec.rb +0 -16
- data/spec/chewy/query/nodes/query_spec.rb +0 -12
- data/spec/chewy/query/nodes/range_spec.rb +0 -32
- data/spec/chewy/query/nodes/raw_spec.rb +0 -11
- data/spec/chewy/query/nodes/regexp_spec.rb +0 -43
- data/spec/chewy/query/nodes/script_spec.rb +0 -15
- data/spec/chewy/query/pagination/kaminari_spec.rb +0 -5
- data/spec/chewy/query/pagination/will_paginate_spec.rb +0 -5
- data/spec/chewy/query/pagination_spec.rb +0 -39
- data/spec/chewy/query_spec.rb +0 -636
- data/spec/chewy/search/parameters/indices_boost_spec.rb +0 -83
data/migration_guide.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Migration guide
|
2
|
+
|
3
|
+
This document outlines the steps you need to take when migrating between major versions of
|
4
|
+
Chewy and Elasticsearch. For simplicity's sake the guide will assume that you're using
|
5
|
+
Chewy alongside a matching Elasticsearch version.
|
6
|
+
|
7
|
+
## Chewy 6/Elasticsearch 6 to Chewy 7/Elasticsearch 7
|
8
|
+
|
9
|
+
In order to upgrade Chewy 6/Elasticsearch 6 to Chewy 7/Elasticsearch 7 in the most seamless manner you have to:
|
10
|
+
|
11
|
+
* Upgrade to the latest 6.x stable releases, namely Chewy 6.0, Elasticsearch 6.8
|
12
|
+
* Study carefully [Breaking changes in 7.0](https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.htmll), make sure your application conforms.
|
13
|
+
* Run your test suite on Chewy 7 / Elasticsearch 7
|
14
|
+
* Run manual tests on Chewy 7 / Elasticsearch 7
|
15
|
+
* Upgrade to Chewy 7
|
16
|
+
* Perform a [rolling upgrade](https://www.elastic.co/guide/en/elasticsearch/reference//rolling-upgrades.html) of Elasticsearch
|
17
|
+
|
18
|
+
## Chewy 5/Elasticsearch 5 to Chewy 6/Elasticsearch 6
|
19
|
+
|
20
|
+
In order to upgrade Chewy 5/Elasticsearch 5 to Chewy 6/Elasticsearch 6 in the most seamless manner you have to:
|
21
|
+
|
22
|
+
* Upgrade to the latest 5.x stable releases, namely Chewy 5.2, Elasticsearch 5.6
|
23
|
+
* [Migrate any multi-typed indexes into single-typed](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/removal-of-types.html)
|
24
|
+
* Using [multi-index queries](https://github.com/toptal/chewy/pull/657) could be helpful
|
25
|
+
* Parent/Child [relationship is deprecated](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/removal-of-types.html#parent-child-mapping-types) in favor of the [join field](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/parent-join.html)
|
26
|
+
* Handle deprecation of `string` type & `not_analyzed` value for the `index` mapping parameter:
|
27
|
+
* replace fields with `{ type: 'string', index: 'not_analyzed'}` by `{type: 'keyword'}`
|
28
|
+
* replace fields with `{ type: 'string', index: 'analyzed'}` by `{type: 'text'}`
|
29
|
+
* `PathHierarchy` tokenizer' param `delimiter` now accepts only one argument, [others should be replaced by character filter ](https://discuss.elastic.co/t/multichar-delimiter-in-path-hierarchy-tokenizer/16203)
|
30
|
+
* Make sure you don't use any other of the [deprecated Elasticsearch 5 features](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/breaking-changes-6.0.html)
|
31
|
+
* Run your test suite on Chewy 6 / Elasticsearch 6
|
32
|
+
* Run manual tests on Chewy 6 / Elasticsearch 6
|
33
|
+
* Upgrade to Chewy 6
|
34
|
+
* Perform a [rolling upgrade](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/rolling-upgrades.html) of Elasticsearch
|
data/spec/chewy/config_spec.rb
CHANGED
@@ -6,9 +6,6 @@ describe Chewy::Config do
|
|
6
6
|
its(:logger) { should be_nil }
|
7
7
|
its(:transport_logger) { should be_nil }
|
8
8
|
its(:transport_logger) { should be_nil }
|
9
|
-
its(:query_mode) { should == :must }
|
10
|
-
its(:filter_mode) { should == :and }
|
11
|
-
its(:post_filter_mode) { should be_nil }
|
12
9
|
its(:root_strategy) { should == :base }
|
13
10
|
its(:request_strategy) { should == :atomic }
|
14
11
|
its(:use_after_commit_callbacks) { should == true }
|
@@ -54,24 +51,6 @@ describe Chewy::Config do
|
|
54
51
|
end
|
55
52
|
end
|
56
53
|
|
57
|
-
describe '#search_class=' do
|
58
|
-
specify do
|
59
|
-
expect { subject.search_class = Chewy::Query }
|
60
|
-
.to change { subject.search_class }
|
61
|
-
.from(be < Chewy::Search::Request)
|
62
|
-
.to(be < Chewy::Query)
|
63
|
-
end
|
64
|
-
|
65
|
-
context do
|
66
|
-
before { hide_const('Kaminari') }
|
67
|
-
|
68
|
-
specify do
|
69
|
-
expect(subject.search_class.included_modules)
|
70
|
-
.to include(Chewy::Search::Pagination::WillPaginate)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
54
|
describe '#search_class' do
|
76
55
|
context 'nothing is defined' do
|
77
56
|
before do
|
@@ -137,5 +116,21 @@ describe Chewy::Config do
|
|
137
116
|
specify do
|
138
117
|
expect(subject.configuration).to include(indices_path: 'app/custom_indices_path')
|
139
118
|
end
|
119
|
+
|
120
|
+
context 'when Rails::VERSION constant is defined' do
|
121
|
+
it 'looks for configuration in "config/chewy.yml"' do
|
122
|
+
module Rails
|
123
|
+
VERSION = '5.1.1'.freeze
|
124
|
+
|
125
|
+
def self.root
|
126
|
+
Pathname.new(__dir__)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
expect(File).to receive(:exist?)
|
131
|
+
.with(Pathname.new(__dir__).join('config', 'chewy.yml'))
|
132
|
+
subject.configuration
|
133
|
+
end
|
134
|
+
end
|
140
135
|
end
|
141
136
|
end
|
@@ -63,7 +63,7 @@ describe Chewy::Fields::Base do
|
|
63
63
|
end
|
64
64
|
|
65
65
|
context 'implicit values' do
|
66
|
-
let(:field) { described_class.new(:name, type: '
|
66
|
+
let(:field) { described_class.new(:name, type: 'integer') }
|
67
67
|
before do
|
68
68
|
field.children.push(described_class.new(:name))
|
69
69
|
field.children.push(described_class.new(:untouched))
|
@@ -87,8 +87,8 @@ describe Chewy::Fields::Base do
|
|
87
87
|
|
88
88
|
describe '#mappings_hash' do
|
89
89
|
let(:field) { described_class.new(:name, type: :object) }
|
90
|
-
let(:fields1) { Array.new(2) { |i| described_class.new("name#{i + 1}", type: "
|
91
|
-
let(:fields2) { Array.new(2) { |i| described_class.new("name#{i + 3}", type: "
|
90
|
+
let(:fields1) { Array.new(2) { |i| described_class.new("name#{i + 1}", type: "integer#{i + 1}") } }
|
91
|
+
let(:fields2) { Array.new(2) { |i| described_class.new("name#{i + 3}", type: "integer#{i + 3}") } }
|
92
92
|
before do
|
93
93
|
fields1.each { |m| field.children.push(m) }
|
94
94
|
fields2.each { |m| fields1[0].children.push(m) }
|
@@ -96,28 +96,30 @@ describe Chewy::Fields::Base do
|
|
96
96
|
|
97
97
|
specify do
|
98
98
|
expect(field.mappings_hash).to eq(name: {type: :object, properties: {
|
99
|
-
name1: {type: '
|
100
|
-
name3: {type: '
|
101
|
-
}}, name2: {type: '
|
99
|
+
name1: {type: 'integer1', fields: {
|
100
|
+
name3: {type: 'integer3'}, name4: {type: 'integer4'}
|
101
|
+
}}, name2: {type: 'integer2'}
|
102
102
|
}})
|
103
103
|
end
|
104
104
|
|
105
105
|
context do
|
106
|
-
let(:field) { described_class.new(:name, type: :
|
107
|
-
let(:fields1)
|
106
|
+
let(:field) { described_class.new(:name, type: :integer) }
|
107
|
+
let(:fields1) do
|
108
|
+
[described_class.new(:name1), described_class.new(:name2, type: 'integer')]
|
109
|
+
end
|
108
110
|
|
109
111
|
specify do
|
110
|
-
expect(field.mappings_hash).to eq(name: {type: :
|
112
|
+
expect(field.mappings_hash).to eq(name: {type: :integer, fields: {
|
111
113
|
name1: {type: 'object', properties: {
|
112
|
-
name3: {type: '
|
113
|
-
}}, name2: {type: '
|
114
|
+
name3: {type: 'integer3'}, name4: {type: 'integer4'}
|
115
|
+
}}, name2: {type: 'integer'}
|
114
116
|
}})
|
115
117
|
end
|
116
118
|
end
|
117
119
|
end
|
118
120
|
|
119
121
|
context 'integration' do
|
120
|
-
context '
|
122
|
+
context 'default field type' do
|
121
123
|
before do
|
122
124
|
stub_index(:events) do
|
123
125
|
define_type :event do
|
@@ -126,26 +128,33 @@ describe Chewy::Fields::Base do
|
|
126
128
|
field :id
|
127
129
|
field :licenses do
|
128
130
|
field :id
|
129
|
-
field :
|
131
|
+
field :created_at, type: 'time'
|
130
132
|
end
|
131
133
|
end
|
132
134
|
end
|
133
135
|
end
|
134
136
|
end
|
135
137
|
|
138
|
+
around do |example|
|
139
|
+
previous_type = Chewy.default_field_type
|
140
|
+
Chewy.default_field_type = 'integer'
|
141
|
+
example.run
|
142
|
+
Chewy.default_field_type = previous_type
|
143
|
+
end
|
144
|
+
|
136
145
|
specify do
|
137
146
|
expect(EventsIndex::Event.mappings_hash).to eq(event: {
|
138
147
|
properties: {
|
139
|
-
id: {type: '
|
148
|
+
id: {type: 'integer'},
|
140
149
|
category: {
|
141
150
|
type: 'object',
|
142
151
|
properties: {
|
143
|
-
id: {type: '
|
152
|
+
id: {type: 'integer'},
|
144
153
|
licenses: {
|
145
154
|
type: 'object',
|
146
155
|
properties: {
|
147
|
-
id: {type: '
|
148
|
-
|
156
|
+
id: {type: 'integer'},
|
157
|
+
created_at: {type: 'time'}
|
149
158
|
}
|
150
159
|
}
|
151
160
|
}
|
@@ -153,83 +162,72 @@ describe Chewy::Fields::Base do
|
|
153
162
|
}
|
154
163
|
})
|
155
164
|
end
|
165
|
+
end
|
156
166
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
type: 'object',
|
171
|
-
properties: {
|
172
|
-
id: {type: 'text'},
|
173
|
-
licenses: {
|
174
|
-
type: 'object',
|
175
|
-
properties: {
|
176
|
-
id: {type: 'text'},
|
177
|
-
name: {type: 'text'}
|
178
|
-
}
|
179
|
-
}
|
180
|
-
}
|
181
|
-
}
|
182
|
-
}
|
183
|
-
})
|
167
|
+
context 'objects, hashes and arrays' do
|
168
|
+
before do
|
169
|
+
stub_index(:events) do
|
170
|
+
define_type :event do
|
171
|
+
field :id
|
172
|
+
field :category do
|
173
|
+
field :id
|
174
|
+
field :licenses do
|
175
|
+
field :id
|
176
|
+
field :name
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
184
180
|
end
|
185
181
|
end
|
186
182
|
|
183
|
+
# rubocop:disable Style/BracesAroundHashParameters
|
187
184
|
specify do
|
188
|
-
expect(EventsIndex::Event.
|
189
|
-
|
190
|
-
)).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => {'id' => 3, 'name' => 'Name'}})
|
185
|
+
expect(EventsIndex::Event.root.compose({
|
186
|
+
id: 1, category: {id: 2, licenses: {id: 3, name: 'Name'}}
|
187
|
+
})).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => {'id' => 3, 'name' => 'Name'}})
|
191
188
|
end
|
192
189
|
|
193
190
|
specify do
|
194
|
-
expect(EventsIndex::Event.
|
191
|
+
expect(EventsIndex::Event.root.compose({id: 1, category: [
|
195
192
|
{id: 2, 'licenses' => {id: 3, name: 'Name1'}},
|
196
193
|
{id: 4, licenses: nil}
|
197
|
-
])).to eq('id' => 1, 'category' => [
|
194
|
+
]})).to eq('id' => 1, 'category' => [
|
198
195
|
{'id' => 2, 'licenses' => {'id' => 3, 'name' => 'Name1'}},
|
199
196
|
{'id' => 4, 'licenses' => nil.as_json}
|
200
197
|
])
|
201
198
|
end
|
202
199
|
|
203
200
|
specify do
|
204
|
-
expect(EventsIndex::Event.
|
201
|
+
expect(EventsIndex::Event.root.compose({'id' => 1, category: {id: 2, licenses: [
|
205
202
|
{id: 3, name: 'Name1'}, {id: 4, name: 'Name2'}
|
206
|
-
]})).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => [
|
203
|
+
]}})).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => [
|
207
204
|
{'id' => 3, 'name' => 'Name1'}, {'id' => 4, 'name' => 'Name2'}
|
208
205
|
]})
|
209
206
|
end
|
210
207
|
|
211
208
|
specify do
|
212
|
-
expect(EventsIndex::Event.
|
209
|
+
expect(EventsIndex::Event.root.compose({id: 1, category: [
|
213
210
|
{id: 2, licenses: [
|
214
211
|
{id: 3, 'name' => 'Name1'}, {id: 4, name: 'Name2'}
|
215
212
|
]},
|
216
213
|
{id: 5, licenses: []}
|
217
|
-
])).to eq('id' => 1, 'category' => [
|
214
|
+
]})).to eq('id' => 1, 'category' => [
|
218
215
|
{'id' => 2, 'licenses' => [
|
219
216
|
{'id' => 3, 'name' => 'Name1'}, {'id' => 4, 'name' => 'Name2'}
|
220
217
|
]},
|
221
218
|
{'id' => 5, 'licenses' => []}
|
222
219
|
])
|
223
220
|
end
|
221
|
+
# rubocop:enable Style/BracesAroundHashParameters
|
224
222
|
|
225
223
|
specify do
|
226
|
-
expect(EventsIndex::Event.
|
224
|
+
expect(EventsIndex::Event.root.compose(
|
227
225
|
double(id: 1, category: double(id: 2, licenses: double(id: 3, name: 'Name')))
|
228
226
|
)).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => {'id' => 3, 'name' => 'Name'}})
|
229
227
|
end
|
230
228
|
|
231
229
|
specify do
|
232
|
-
expect(EventsIndex::Event.
|
230
|
+
expect(EventsIndex::Event.root.compose(double(id: 1, category: [
|
233
231
|
double(id: 2, licenses: double(id: 3, name: 'Name1')),
|
234
232
|
double(id: 4, licenses: nil)
|
235
233
|
]))).to eq('id' => 1, 'category' => [
|
@@ -239,7 +237,7 @@ describe Chewy::Fields::Base do
|
|
239
237
|
end
|
240
238
|
|
241
239
|
specify do
|
242
|
-
expect(EventsIndex::Event.
|
240
|
+
expect(EventsIndex::Event.root.compose(double(id: 1, category: double(id: 2, licenses: [
|
243
241
|
double(id: 3, name: 'Name1'), double(id: 4, name: 'Name2')
|
244
242
|
])))).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => [
|
245
243
|
{'id' => 3, 'name' => 'Name1'}, {'id' => 4, 'name' => 'Name2'}
|
@@ -247,7 +245,7 @@ describe Chewy::Fields::Base do
|
|
247
245
|
end
|
248
246
|
|
249
247
|
specify do
|
250
|
-
expect(EventsIndex::Event.
|
248
|
+
expect(EventsIndex::Event.root.compose(double(id: 1, category: [
|
251
249
|
double(id: 2, licenses: [
|
252
250
|
double(id: 3, name: 'Name1'), double(id: 4, name: 'Name2')
|
253
251
|
]),
|
@@ -265,11 +263,11 @@ describe Chewy::Fields::Base do
|
|
265
263
|
before do
|
266
264
|
stub_index(:events) do
|
267
265
|
define_type :event do
|
268
|
-
field :id
|
266
|
+
field :id, type: 'integer'
|
269
267
|
field :category, value: -> { categories } do
|
270
|
-
field :id
|
268
|
+
field :id, type: 'integer'
|
271
269
|
field :licenses, value: -> { license } do
|
272
|
-
field :id
|
270
|
+
field :id, type: 'integer'
|
273
271
|
field :name
|
274
272
|
end
|
275
273
|
end
|
@@ -278,7 +276,7 @@ describe Chewy::Fields::Base do
|
|
278
276
|
end
|
279
277
|
|
280
278
|
specify do
|
281
|
-
expect(EventsIndex::Event.
|
279
|
+
expect(EventsIndex::Event.root.compose(
|
282
280
|
double(id: 1, categories: double(id: 2, license: double(id: 3, name: 'Name')))
|
283
281
|
)).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => {'id' => 3, 'name' => 'Name'}})
|
284
282
|
end
|
@@ -288,8 +286,8 @@ describe Chewy::Fields::Base do
|
|
288
286
|
before do
|
289
287
|
stub_index(:events) do
|
290
288
|
define_type :event do
|
291
|
-
field :id
|
292
|
-
field :name, type: '
|
289
|
+
field :id, type: 'integer'
|
290
|
+
field :name, type: 'integer' do
|
293
291
|
field :raw, analyzer: 'my_own'
|
294
292
|
end
|
295
293
|
field :category, type: 'object'
|
@@ -300,11 +298,11 @@ describe Chewy::Fields::Base do
|
|
300
298
|
specify do
|
301
299
|
expect(EventsIndex::Event.mappings_hash).to eq(event: {
|
302
300
|
properties: {
|
303
|
-
id: {type: '
|
301
|
+
id: {type: 'integer'},
|
304
302
|
name: {
|
305
|
-
type: '
|
303
|
+
type: 'integer',
|
306
304
|
fields: {
|
307
|
-
raw: {analyzer: 'my_own', type:
|
305
|
+
raw: {analyzer: 'my_own', type: Chewy.default_field_type}
|
308
306
|
}
|
309
307
|
},
|
310
308
|
category: {type: 'object'}
|
@@ -313,7 +311,7 @@ describe Chewy::Fields::Base do
|
|
313
311
|
end
|
314
312
|
|
315
313
|
specify do
|
316
|
-
expect(EventsIndex::Event.
|
314
|
+
expect(EventsIndex::Event.root.compose(
|
317
315
|
double(id: 1, name: 'Jonny', category: double(id: 2, as_json: {'name' => 'Borogoves'}))
|
318
316
|
)).to eq(
|
319
317
|
'id' => 1,
|
@@ -323,7 +321,7 @@ describe Chewy::Fields::Base do
|
|
323
321
|
end
|
324
322
|
|
325
323
|
specify do
|
326
|
-
expect(EventsIndex::Event.
|
324
|
+
expect(EventsIndex::Event.root.compose(
|
327
325
|
double(id: 1, name: 'Jonny', category: [
|
328
326
|
double(id: 2, as_json: {'name' => 'Borogoves1'}),
|
329
327
|
double(id: 3, as_json: {'name' => 'Borogoves2'})
|
@@ -388,7 +386,7 @@ describe Chewy::Fields::Base do
|
|
388
386
|
end
|
389
387
|
|
390
388
|
specify do
|
391
|
-
expect(CountriesIndex::Country.
|
389
|
+
expect(CountriesIndex::Country.root.compose(country_with_cities)).to eq('id' => 1, 'cities' => [
|
392
390
|
{'id' => 1, 'name' => 'City1'}, {'id' => 2, 'name' => 'City2'}
|
393
391
|
])
|
394
392
|
end
|
@@ -407,7 +405,7 @@ describe Chewy::Fields::Base do
|
|
407
405
|
end
|
408
406
|
|
409
407
|
specify do
|
410
|
-
expect(CitiesIndex::City.
|
408
|
+
expect(CitiesIndex::City.root.compose(
|
411
409
|
City.create!(id: 1, country: Country.create!(id: 1, name: 'Country'))
|
412
410
|
)).to eq('id' => 1, 'country' => {'id' => 1, 'name' => 'Country'})
|
413
411
|
end
|
@@ -5,7 +5,7 @@ describe Chewy::Fields::Root do
|
|
5
5
|
|
6
6
|
describe '#dynamic_template' do
|
7
7
|
specify do
|
8
|
-
field.dynamic_template 'hello', type: '
|
8
|
+
field.dynamic_template 'hello', type: 'keyword'
|
9
9
|
field.dynamic_template 'hello*', :integer
|
10
10
|
field.dynamic_template 'hello.*'
|
11
11
|
field.dynamic_template(/hello/)
|
@@ -14,7 +14,7 @@ describe Chewy::Fields::Root do
|
|
14
14
|
field.dynamic_template(/hello\..*/)
|
15
15
|
|
16
16
|
expect(field.mappings_hash).to eq(product: {dynamic_templates: [
|
17
|
-
{template_1: {mapping: {type: '
|
17
|
+
{template_1: {mapping: {type: 'keyword'}, match: 'hello'}},
|
18
18
|
{template_2: {mapping: {}, match_mapping_type: 'integer', match: 'hello*'}},
|
19
19
|
{template_3: {mapping: {}, path_match: 'hello.*'}},
|
20
20
|
{template_4: {mapping: {}, match: 'hello', match_pattern: 'regexp'}},
|
@@ -32,10 +32,10 @@ describe Chewy::Fields::Root do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
specify do
|
35
|
-
field.dynamic_template 'hello', type: '
|
35
|
+
field.dynamic_template 'hello', type: 'keyword'
|
36
36
|
expect(field.mappings_hash).to eq(product: {dynamic_templates: [
|
37
37
|
{template_42: {mapping: {}, match: ''}},
|
38
|
-
{template_1: {mapping: {type: '
|
38
|
+
{template_1: {mapping: {type: 'keyword'}, match: 'hello'}}
|
39
39
|
]})
|
40
40
|
end
|
41
41
|
end
|
@@ -53,11 +53,11 @@ describe Chewy::Fields::Root do
|
|
53
53
|
let(:city) { City.new(name: 'London', rating: 100) }
|
54
54
|
|
55
55
|
specify do
|
56
|
-
expect(PlacesIndex::City.
|
56
|
+
expect(PlacesIndex::City.root.compose(city))
|
57
57
|
.to match(hash_including('name' => 'London', 'rating' => 100))
|
58
58
|
end
|
59
59
|
specify do
|
60
|
-
expect(PlacesIndex::City.
|
60
|
+
expect(PlacesIndex::City.root.compose(city, fields: %i[name borogoves]))
|
61
61
|
.to eq('name' => 'London')
|
62
62
|
end
|
63
63
|
end
|
@@ -74,11 +74,11 @@ describe Chewy::Fields::Root do
|
|
74
74
|
let(:city) { double(name: 'London', rating: 100) }
|
75
75
|
|
76
76
|
specify do
|
77
|
-
expect(PlacesIndex::City.
|
77
|
+
expect(PlacesIndex::City.root.compose(city))
|
78
78
|
.to eq('name' => 'London', 'rating' => 100)
|
79
79
|
end
|
80
80
|
specify do
|
81
|
-
expect(PlacesIndex::City.
|
81
|
+
expect(PlacesIndex::City.root.compose(city, fields: %i[name borogoves]))
|
82
82
|
.to eq('name' => 'London')
|
83
83
|
end
|
84
84
|
end
|
@@ -95,12 +95,12 @@ describe Chewy::Fields::Root do
|
|
95
95
|
let(:city) { double(name: 'London', rating: 100) }
|
96
96
|
|
97
97
|
specify do
|
98
|
-
expect(PlacesIndex::City.
|
98
|
+
expect(PlacesIndex::City.root.compose(city))
|
99
99
|
.to eq('name' => 'LondonModified', 'rating' => 101)
|
100
100
|
end
|
101
101
|
|
102
102
|
specify do
|
103
|
-
expect(PlacesIndex::City.
|
103
|
+
expect(PlacesIndex::City.root.compose(city, fields: %i[name borogoves]))
|
104
104
|
.to eq('name' => 'LondonModified')
|
105
105
|
end
|
106
106
|
end
|
@@ -120,12 +120,12 @@ describe Chewy::Fields::Root do
|
|
120
120
|
let(:city) { double(name: 'London', rating: 100) }
|
121
121
|
|
122
122
|
specify do
|
123
|
-
expect(PlacesIndex::City.
|
123
|
+
expect(PlacesIndex::City.root.compose(city))
|
124
124
|
.to eq('name' => 'LondonModifiedModified', 'rating' => 101)
|
125
125
|
end
|
126
126
|
|
127
127
|
specify do
|
128
|
-
expect(PlacesIndex::City.
|
128
|
+
expect(PlacesIndex::City.root.compose(city, fields: %i[name borogoves]))
|
129
129
|
.to eq('name' => 'LondonModifiedModified')
|
130
130
|
end
|
131
131
|
end
|
@@ -141,7 +141,7 @@ describe Chewy::Fields::Root do
|
|
141
141
|
end
|
142
142
|
|
143
143
|
specify do
|
144
|
-
expect(PlacesIndex::City.
|
144
|
+
expect(PlacesIndex::City.root.child_hash).to match(
|
145
145
|
name: an_instance_of(Chewy::Fields::Base).and(have_attributes(name: :name)),
|
146
146
|
rating: an_instance_of(Chewy::Fields::Base).and(have_attributes(name: :rating))
|
147
147
|
)
|