chewy 5.2.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +36 -10
  3. data/CHANGELOG.md +219 -326
  4. data/Gemfile +1 -1
  5. data/README.md +9 -21
  6. data/chewy.gemspec +1 -1
  7. data/gemfiles/rails.6.1.activerecord.gemfile +1 -1
  8. data/lib/chewy/config.rb +2 -20
  9. data/lib/chewy/fields/base.rb +0 -6
  10. data/lib/chewy/index.rb +2 -0
  11. data/lib/chewy/index/actions.rb +5 -1
  12. data/lib/chewy/multi_search.rb +62 -0
  13. data/lib/chewy/search.rb +1 -4
  14. data/lib/chewy/search/pagination/will_paginate.rb +1 -1
  15. data/lib/chewy/search/parameters/none.rb +1 -3
  16. data/lib/chewy/search/request.rb +25 -24
  17. data/lib/chewy/search/scrolling.rb +4 -1
  18. data/lib/chewy/type.rb +4 -1
  19. data/lib/chewy/type/adapter/orm.rb +6 -3
  20. data/lib/chewy/type/import.rb +1 -0
  21. data/lib/chewy/type/syncer.rb +4 -5
  22. data/lib/chewy/type/witchcraft.rb +3 -1
  23. data/lib/chewy/type/wrapper.rb +11 -1
  24. data/lib/chewy/version.rb +1 -1
  25. data/migration_guide.md +18 -0
  26. data/spec/chewy/config_spec.rb +0 -21
  27. data/spec/chewy/index/actions_spec.rb +24 -0
  28. data/spec/chewy/index_spec.rb +16 -39
  29. data/spec/chewy/journal_spec.rb +21 -17
  30. data/spec/chewy/minitest/search_index_receiver_spec.rb +11 -9
  31. data/spec/chewy/multi_search_spec.rb +85 -0
  32. data/spec/chewy/rake_helper_spec.rb +102 -87
  33. data/spec/chewy/rspec/update_index_spec.rb +47 -46
  34. data/spec/chewy/runtime_spec.rb +2 -2
  35. data/spec/chewy/search/parameters/indices_spec.rb +6 -7
  36. data/spec/chewy/search/parameters/none_spec.rb +1 -1
  37. data/spec/chewy/search/parameters_spec.rb +1 -1
  38. data/spec/chewy/search/request_spec.rb +82 -67
  39. data/spec/chewy/search/response_spec.rb +19 -15
  40. data/spec/chewy/search/scrolling_spec.rb +25 -16
  41. data/spec/chewy/search_spec.rb +45 -41
  42. data/spec/chewy/stash_spec.rb +14 -12
  43. data/spec/chewy/type/adapter/active_record_spec.rb +13 -1
  44. data/spec/chewy/type/import/bulk_builder_spec.rb +9 -94
  45. data/spec/chewy/type/import/journal_builder_spec.rb +9 -7
  46. data/spec/chewy/type/mapping_spec.rb +3 -1
  47. data/spec/chewy/type/witchcraft_spec.rb +15 -0
  48. data/spec/chewy/type/wrapper_spec.rb +3 -1
  49. data/spec/chewy_spec.rb +0 -7
  50. data/spec/spec_helper.rb +0 -7
  51. data/spec/support/active_record.rb +20 -0
  52. metadata +8 -78
  53. data/LEGACY_DSL.md +0 -497
  54. data/gemfiles/ruby3.gemfile +0 -10
  55. data/lib/chewy/query.rb +0 -1142
  56. data/lib/chewy/query/compose.rb +0 -68
  57. data/lib/chewy/query/criteria.rb +0 -191
  58. data/lib/chewy/query/filters.rb +0 -244
  59. data/lib/chewy/query/loading.rb +0 -110
  60. data/lib/chewy/query/nodes/and.rb +0 -25
  61. data/lib/chewy/query/nodes/base.rb +0 -17
  62. data/lib/chewy/query/nodes/bool.rb +0 -34
  63. data/lib/chewy/query/nodes/equal.rb +0 -34
  64. data/lib/chewy/query/nodes/exists.rb +0 -20
  65. data/lib/chewy/query/nodes/expr.rb +0 -28
  66. data/lib/chewy/query/nodes/field.rb +0 -110
  67. data/lib/chewy/query/nodes/has_child.rb +0 -15
  68. data/lib/chewy/query/nodes/has_parent.rb +0 -15
  69. data/lib/chewy/query/nodes/has_relation.rb +0 -59
  70. data/lib/chewy/query/nodes/match_all.rb +0 -11
  71. data/lib/chewy/query/nodes/missing.rb +0 -20
  72. data/lib/chewy/query/nodes/not.rb +0 -25
  73. data/lib/chewy/query/nodes/or.rb +0 -25
  74. data/lib/chewy/query/nodes/prefix.rb +0 -19
  75. data/lib/chewy/query/nodes/query.rb +0 -20
  76. data/lib/chewy/query/nodes/range.rb +0 -63
  77. data/lib/chewy/query/nodes/raw.rb +0 -15
  78. data/lib/chewy/query/nodes/regexp.rb +0 -35
  79. data/lib/chewy/query/nodes/script.rb +0 -20
  80. data/lib/chewy/query/pagination.rb +0 -25
  81. data/spec/chewy/query/criteria_spec.rb +0 -700
  82. data/spec/chewy/query/filters_spec.rb +0 -201
  83. data/spec/chewy/query/loading_spec.rb +0 -124
  84. data/spec/chewy/query/nodes/and_spec.rb +0 -12
  85. data/spec/chewy/query/nodes/bool_spec.rb +0 -14
  86. data/spec/chewy/query/nodes/equal_spec.rb +0 -32
  87. data/spec/chewy/query/nodes/exists_spec.rb +0 -18
  88. data/spec/chewy/query/nodes/has_child_spec.rb +0 -59
  89. data/spec/chewy/query/nodes/has_parent_spec.rb +0 -59
  90. data/spec/chewy/query/nodes/match_all_spec.rb +0 -11
  91. data/spec/chewy/query/nodes/missing_spec.rb +0 -16
  92. data/spec/chewy/query/nodes/not_spec.rb +0 -14
  93. data/spec/chewy/query/nodes/or_spec.rb +0 -12
  94. data/spec/chewy/query/nodes/prefix_spec.rb +0 -16
  95. data/spec/chewy/query/nodes/query_spec.rb +0 -12
  96. data/spec/chewy/query/nodes/range_spec.rb +0 -32
  97. data/spec/chewy/query/nodes/raw_spec.rb +0 -11
  98. data/spec/chewy/query/nodes/regexp_spec.rb +0 -43
  99. data/spec/chewy/query/nodes/script_spec.rb +0 -15
  100. data/spec/chewy/query/pagination/kaminari_spec.rb +0 -5
  101. data/spec/chewy/query/pagination/will_paginate_spec.rb +0 -5
  102. data/spec/chewy/query/pagination_spec.rb +0 -39
  103. data/spec/chewy/query_spec.rb +0 -637
@@ -67,6 +67,7 @@ module Chewy
67
67
  # @option options [String] suffix an index name suffix, used for zero-downtime reset mostly, no suffix by default
68
68
  # @option options [Integer] bulk_size bulk API chunk size in bytes; if passed, the request is performed several times for each chunk, empty by default
69
69
  # @option options [Integer] batch_size passed to the adapter import method, used to split imported objects in chunks, 1000 by default
70
+ # @option options [Boolean] direct_import skips object reloading in ORM adapter, `false` by default
70
71
  # @option options [true, false] journal enables imported objects journaling, false by default
71
72
  # @option options [Array<Symbol, String>] update_fields list of fields for the partial import, empty by default
72
73
  # @option options [true, false] update_failover enables full objects reimport in cases of partial update errors, `true` by default
@@ -2,7 +2,7 @@ module Chewy
2
2
  class Type
3
3
  # This class is able to find missing and outdated documents in the ES
4
4
  # comparing ids from the data source and the ES index. Also, if `outdated_sync_field`
5
- # existss in the index definition, it performs comparison of this field
5
+ # exists in the index definition, it performs comparison of this field
6
6
  # values for each source object and corresponding ES document. Usually,
7
7
  # this field is `updated_at` and if its value in the source is not equal
8
8
  # to the value in the index - this means that this document outdated and
@@ -205,10 +205,9 @@ module Chewy
205
205
  return @outdated_sync_field_type if instance_variable_defined?(:@outdated_sync_field_type)
206
206
  return unless @type.outdated_sync_field
207
207
 
208
- mappings = @type.client.indices.get_mapping(
209
- index: @type.index_name,
210
- type: @type.type_name
211
- ).values.first.fetch('mappings', {})
208
+ args = {index: @type.index_name, type: @type.type_name}
209
+ args[:include_type_name] = true if Runtime.version >= '6.7.0'
210
+ mappings = @type.client.indices.get_mapping(**args).values.first.fetch('mappings', {})
212
211
 
213
212
  @outdated_sync_field_type = mappings
214
213
  .fetch(@type.type_name, {})
@@ -79,7 +79,9 @@ module Chewy
79
79
  if field.children.present? && !field.multi_field?
80
80
  <<-RUBY
81
81
  (result#{nesting} = #{fetcher}
82
- if result#{nesting}.respond_to?(:to_ary)
82
+ if result#{nesting}.nil?
83
+ nil
84
+ elsif result#{nesting}.respond_to?(:to_ary)
83
85
  result#{nesting}.map do |object#{nesting}|
84
86
  #{composed_values(field, nesting)}
85
87
  end
@@ -49,6 +49,8 @@ module Chewy
49
49
  m = method.to_s
50
50
  if (name = highlight_name(m))
51
51
  highlight(name)
52
+ elsif (name = highlight_names(m))
53
+ highlights(name)
52
54
  elsif @attributes.key?(m)
53
55
  @attributes[m]
54
56
  elsif attribute_defined?(m)
@@ -60,7 +62,7 @@ module Chewy
60
62
 
61
63
  def respond_to_missing?(method, include_private = false)
62
64
  m = method.to_s
63
- highlight_name(m) || @attributes.key?(m) || attribute_defined?(m) || super
65
+ highlight_name(m) || highlight_names(m) || @attributes.key?(m) || attribute_defined?(m) || super
64
66
  end
65
67
 
66
68
  private
@@ -69,6 +71,10 @@ module Chewy
69
71
  method.sub(/_highlight\z/, '') if method.end_with?('_highlight')
70
72
  end
71
73
 
74
+ def highlight_names(method)
75
+ method.sub(/_highlights\z/, '') if method.end_with?('_highlights')
76
+ end
77
+
72
78
  def attribute_defined?(attribute)
73
79
  self.class.root && self.class.root.children.find { |a| a.name.to_s == attribute }.present?
74
80
  end
@@ -77,6 +83,10 @@ module Chewy
77
83
  _data['highlight'][attribute].first if highlight?(attribute)
78
84
  end
79
85
 
86
+ def highlights(attribute)
87
+ _data['highlight'][attribute] if highlight?(attribute)
88
+ end
89
+
80
90
  def highlight?(attribute)
81
91
  _data.key?('highlight') && _data['highlight'].key?(attribute)
82
92
  end
data/lib/chewy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Chewy
2
- VERSION = '5.2.0'.freeze
2
+ VERSION = '6.0.0'.freeze
3
3
  end
@@ -0,0 +1,18 @@
1
+ # Migration guide
2
+
3
+ ## Chewy 5 / ES 5 to Chewy 6 / ES 6
4
+
5
+ In order to upgrade chewy5/ES5 to chewy6/ES6 in the most seamless manner you have to:
6
+ * Upgrade to the latest 5.x stable releases: Chewy 5.2, ES 5.6
7
+ * [Migrate any multi-typed indexes into single-typed](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/removal-of-types.html)
8
+ * Using [multi-index queries](https://github.com/toptal/chewy/pull/657) could be helpful
9
+ * 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)
10
+ * Handle deprecation of `string` type & `not_analyzed` value for the `index` mapping parameter:
11
+ * replace fields with `{ type: 'string', index: 'not_analyzed'}` by `{type: 'keyword'}`
12
+ * replace fields with `{ type: 'string', index: 'analyzed'}` by `{type: 'text'}`
13
+ * `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)
14
+ * Make sure you don't use any other of the [deprecated ES5 features](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/breaking-changes-6.0.html)
15
+ * Run your test suite on ES6
16
+ * Run manual tests on ES6
17
+ * Perform a [rolling upgrade](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/rolling-upgrades.html) of Elasticsearch
18
+ * Upgrade to Chewy 6
@@ -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
@@ -281,6 +281,18 @@ describe Chewy::Index::Actions do
281
281
 
282
282
  specify { expect(CitiesIndex.import).to eq(true) }
283
283
 
284
+ specify 'with an empty array' do
285
+ expect(CitiesIndex).not_to receive(:exists?)
286
+ expect(CitiesIndex).not_to receive(:create!)
287
+ expect(CitiesIndex.import([])).to eq(true)
288
+ end
289
+
290
+ specify 'with an empty relation' do
291
+ expect(CitiesIndex).not_to receive(:exists?)
292
+ expect(CitiesIndex).not_to receive(:create!)
293
+ expect(CitiesIndex.import(City.where('1 = 2'))).to eq(true)
294
+ end
295
+
284
296
  context do
285
297
  before do
286
298
  stub_index(:cities) do
@@ -305,6 +317,18 @@ describe Chewy::Index::Actions do
305
317
 
306
318
  specify { expect(CitiesIndex.import!).to eq(true) }
307
319
 
320
+ specify 'with an empty array' do
321
+ expect(CitiesIndex).not_to receive(:exists?)
322
+ expect(CitiesIndex).not_to receive(:create!)
323
+ expect(CitiesIndex.import!([])).to eq(true)
324
+ end
325
+
326
+ specify 'with an empty relation' do
327
+ expect(CitiesIndex).not_to receive(:exists?)
328
+ expect(CitiesIndex).not_to receive(:create!)
329
+ expect(CitiesIndex.import!(City.where('1 = 2'))).to eq(true)
330
+ end
331
+
308
332
  context do
309
333
  before do
310
334
  stub_index(:cities) do
@@ -12,8 +12,11 @@ describe Chewy::Index do
12
12
  stub_model(:city)
13
13
  stub_model(:country)
14
14
 
15
- stub_index(:places) do
15
+ stub_index(:cities) do
16
16
  define_type City
17
+ end
18
+
19
+ stub_index(:countries) do
17
20
  define_type Country
18
21
  end
19
22
  end
@@ -22,23 +25,23 @@ describe Chewy::Index do
22
25
  let!(:countries) { Array.new(2) { |i| Country.create! id: i + 1 } }
23
26
 
24
27
  specify do
25
- expect { PlacesIndex.import }.to update_index(PlacesIndex::City).and_reindex(cities)
26
- expect { PlacesIndex.import }.to update_index(PlacesIndex::Country).and_reindex(countries)
28
+ expect { CitiesIndex.import }.to update_index(CitiesIndex).and_reindex(cities)
29
+ expect { CountriesIndex.import }.to update_index(CountriesIndex).and_reindex(countries)
27
30
  end
28
31
 
29
32
  specify do
30
- expect { PlacesIndex.import city: cities.first }.to update_index(PlacesIndex::City).and_reindex(cities.first).only
31
- expect { PlacesIndex.import city: cities.first }.to update_index(PlacesIndex::Country).and_reindex(countries)
33
+ expect { CitiesIndex.import city: cities.first }.to update_index(CitiesIndex).and_reindex(cities.first).only
34
+ expect { CountriesIndex.import city: cities.first }.to update_index(CountriesIndex).and_reindex(countries)
32
35
  end
33
36
 
34
37
  specify do
35
- expect { PlacesIndex.import city: cities.first, country: countries.last }.to update_index(PlacesIndex::City).and_reindex(cities.first).only
36
- expect { PlacesIndex.import city: cities.first, country: countries.last }.to update_index(PlacesIndex::Country).and_reindex(countries.last).only
38
+ expect { CitiesIndex.import city: cities.first, country: countries.last }.to update_index(CitiesIndex).and_reindex(cities.first).only
39
+ expect { CountriesIndex.import city: cities.first, country: countries.last }.to update_index(CountriesIndex).and_reindex(countries.last).only
37
40
  end
38
41
 
39
42
  specify do
40
- expect(PlacesIndex.client).to receive(:bulk).with(hash_including(refresh: false)).twice
41
- PlacesIndex.import city: cities.first, refresh: false
43
+ expect(CitiesIndex.client).to receive(:bulk).with(hash_including(refresh: false)).once
44
+ CitiesIndex.import city: cities.first, refresh: false
42
45
  end
43
46
  end
44
47
 
@@ -101,43 +104,27 @@ describe Chewy::Index do
101
104
 
102
105
  context do
103
106
  before { stub_class('City') }
104
- before { stub_class('City::District', City) }
107
+ before { stub_class('Country') }
105
108
 
106
109
  specify do
107
110
  expect do
108
111
  Kernel.eval <<-DUMMY_CITY_INDEX
109
- class DummyCityIndex < Chewy::Index
112
+ class DummyCityIndex2 < Chewy::Index
110
113
  define_type City
111
- define_type City::District
114
+ define_type Country
112
115
  end
113
116
  DUMMY_CITY_INDEX
114
- end.not_to raise_error
115
- end
117
+ end.to raise_error(/Multiple types are deprecated/)
116
118
 
117
- specify do
118
119
  expect do
119
120
  Kernel.eval <<-DUMMY_CITY_INDEX
120
121
  class DummyCityIndex2 < Chewy::Index
121
- define_type City
122
122
  define_type City::Nothing
123
123
  end
124
124
  DUMMY_CITY_INDEX
125
125
  end.to raise_error(NameError)
126
126
  end
127
127
  end
128
-
129
- context 'type methods should be deprecated and can\'t redefine existing ones' do
130
- before do
131
- stub_index(:places) do
132
- def self.city; end
133
- define_type :city
134
- define_type :country
135
- end
136
- end
137
-
138
- specify { expect(PlacesIndex.city).to be_nil }
139
- specify { expect(PlacesIndex::Country).to be < Chewy::Type }
140
- end
141
128
  end
142
129
 
143
130
  describe '.type_hash' do
@@ -248,16 +235,6 @@ describe Chewy::Index do
248
235
  end
249
236
  end.mappings_hash).to eq(mappings: {document: {properties: {date: {type: 'date'}}}})
250
237
  end
251
- specify do
252
- expect(stub_index(:documents) do
253
- define_type :document do
254
- field :name
255
- end
256
- define_type :document2 do
257
- field :name
258
- end
259
- end.mappings_hash[:mappings].keys).to match_array(%i[document document2])
260
- end
261
238
  end
262
239
 
263
240
  describe '.specification_hash' do
@@ -6,16 +6,18 @@ describe Chewy::Journal do
6
6
  context namespace.present? ? 'with namespace' : 'without namespace' do
7
7
  before do
8
8
  stub_model(:city) do
9
- update_index "#{namespace}places#city", :self
9
+ update_index "#{namespace}cities", :self
10
10
  end
11
11
  stub_model(:country) do
12
- update_index "#{namespace}places#country", :self
12
+ update_index "#{namespace}countries", :self
13
13
  end
14
14
 
15
- stub_index("#{namespace}places") do
15
+ stub_index("#{namespace}cities") do
16
16
  define_type City do
17
17
  default_import_options journal: true
18
18
  end
19
+ end
20
+ stub_index("#{namespace}countries") do
19
21
  define_type Country do
20
22
  default_import_options journal: true
21
23
  end
@@ -41,7 +43,8 @@ describe Chewy::Journal do
41
43
  end
42
44
 
43
45
  specify do
44
- places_index = namespace.present? ? Namespace::PlacesIndex : PlacesIndex
46
+ cities_index = namespace.present? ? Namespace::CitiesIndex : CitiesIndex
47
+ countries_index = namespace.present? ? Namespace::CountriesIndex : CountriesIndex
45
48
  Chewy.strategy(:urgent) do
46
49
  cities = Array.new(2) { |i| City.create!(id: i + 1) }
47
50
  countries = Array.new(2) { |i| Country.create!(id: i + 1) }
@@ -49,7 +52,8 @@ describe Chewy::Journal do
49
52
 
50
53
  Timecop.freeze(import_time)
51
54
 
52
- places_index.import
55
+ cities_index.import
56
+ countries_index.import
53
57
 
54
58
  expect(Chewy::Stash::Journal.exists?).to eq true
55
59
 
@@ -62,63 +66,63 @@ describe Chewy::Journal do
62
66
  journal_entries = Chewy::Stash::Journal.order(:created_at).hits.map { |r| r['_source'] }
63
67
  expected_journal = [
64
68
  {
65
- 'index_name' => "#{namespace}places",
69
+ 'index_name' => "#{namespace}cities",
66
70
  'type_name' => 'city',
67
71
  'action' => 'index',
68
72
  'references' => ['1'].map(&Base64.method(:encode64)),
69
73
  'created_at' => time.utc.as_json
70
74
  },
71
75
  {
72
- 'index_name' => "#{namespace}places",
76
+ 'index_name' => "#{namespace}cities",
73
77
  'type_name' => 'city',
74
78
  'action' => 'index',
75
79
  'references' => ['2'].map(&Base64.method(:encode64)),
76
80
  'created_at' => time.utc.as_json
77
81
  },
78
82
  {
79
- 'index_name' => "#{namespace}places",
83
+ 'index_name' => "#{namespace}countries",
80
84
  'type_name' => 'country',
81
85
  'action' => 'index',
82
86
  'references' => ['1'].map(&Base64.method(:encode64)),
83
87
  'created_at' => time.utc.as_json
84
88
  },
85
89
  {
86
- 'index_name' => "#{namespace}places",
90
+ 'index_name' => "#{namespace}countries",
87
91
  'type_name' => 'country',
88
92
  'action' => 'index',
89
93
  'references' => ['2'].map(&Base64.method(:encode64)),
90
94
  'created_at' => time.utc.as_json
91
95
  },
92
96
  {
93
- 'index_name' => "#{namespace}places",
97
+ 'index_name' => "#{namespace}countries",
94
98
  'type_name' => 'country',
95
99
  'action' => 'index',
96
100
  'references' => ['3'].map(&Base64.method(:encode64)),
97
101
  'created_at' => time.utc.as_json
98
102
  },
99
103
  {
100
- 'index_name' => "#{namespace}places",
104
+ 'index_name' => "#{namespace}cities",
101
105
  'type_name' => 'city',
102
106
  'action' => 'index',
103
107
  'references' => %w[1 2].map(&Base64.method(:encode64)),
104
108
  'created_at' => import_time.utc.as_json
105
109
  },
106
110
  {
107
- 'index_name' => "#{namespace}places",
111
+ 'index_name' => "#{namespace}countries",
108
112
  'type_name' => 'country',
109
113
  'action' => 'index',
110
114
  'references' => %w[1 2 3].map(&Base64.method(:encode64)),
111
115
  'created_at' => import_time.utc.as_json
112
116
  },
113
117
  {
114
- 'index_name' => "#{namespace}places",
118
+ 'index_name' => "#{namespace}cities",
115
119
  'type_name' => 'city',
116
120
  'action' => 'index',
117
121
  'references' => ['1'].map(&Base64.method(:encode64)),
118
122
  'created_at' => update_time.utc.as_json
119
123
  },
120
124
  {
121
- 'index_name' => "#{namespace}places",
125
+ 'index_name' => "#{namespace}countries",
122
126
  'type_name' => 'country',
123
127
  'action' => 'delete',
124
128
  'references' => ['2'].map(&Base64.method(:encode64)),
@@ -133,11 +137,11 @@ describe Chewy::Journal do
133
137
  expect(journal_entries.size).to eq 4
134
138
 
135
139
  # simulate lost data
136
- Chewy.client.delete(index: "#{Chewy.settings[:prefix]}_places", type: 'city', id: 1, refresh: true)
137
- expect(places_index::City.count).to eq 1
140
+ Chewy.client.delete(index: "#{Chewy.settings[:prefix]}_cities", type: 'city', id: 1, refresh: true)
141
+ expect(cities_index.count).to eq 1
138
142
 
139
143
  described_class.new.apply(time)
140
- expect(places_index::City.count).to eq 2
144
+ expect(cities_index.count).to eq 2
141
145
 
142
146
  clean_response = described_class.new.clean(import_time)
143
147
  expect(clean_response['deleted'] || clean_response['_indices']['_all']['deleted']).to eq 7
@@ -29,7 +29,9 @@ describe :search_index_receiver do
29
29
  define_type :fizz do
30
30
  root value: ->(_o) { {} }
31
31
  end
32
+ end
32
33
 
34
+ stub_index(:dummies2) do
33
35
  define_type :buzz do
34
36
  root value: ->(_o) { {} }
35
37
  end
@@ -39,15 +41,15 @@ describe :search_index_receiver do
39
41
  context 'catch' do
40
42
  specify 'archives more than one type' do
41
43
  receiver.catch search_request(2), DummiesIndex::Fizz
42
- receiver.catch search_request(3), DummiesIndex::Buzz
43
- expect(receiver.indexes.keys).to match_array([DummiesIndex::Fizz, DummiesIndex::Buzz])
44
+ receiver.catch search_request(3), Dummies2Index::Buzz
45
+ expect(receiver.indexes.keys).to match_array([DummiesIndex::Fizz, Dummies2Index::Buzz])
44
46
  end
45
47
  end
46
48
 
47
49
  context 'indexes_for' do
48
50
  before do
49
51
  receiver.catch search_request(2), DummiesIndex::Fizz
50
- receiver.catch search_request(3), DummiesIndex::Buzz
52
+ receiver.catch search_request(3), Dummies2Index::Buzz
51
53
  end
52
54
 
53
55
  specify 'returns indexes for a specific type' do
@@ -56,7 +58,7 @@ describe :search_index_receiver do
56
58
 
57
59
  specify 'returns only indexes for all types' do
58
60
  index_responses = receiver.indexes
59
- expect(index_responses.keys).to match_array([DummiesIndex::Fizz, DummiesIndex::Buzz])
61
+ expect(index_responses.keys).to match_array([DummiesIndex::Fizz, Dummies2Index::Buzz])
60
62
  expect(parse_request(index_responses.values.flatten)).to match_array([1, 2, 1, 2, 3])
61
63
  end
62
64
  end
@@ -64,16 +66,16 @@ describe :search_index_receiver do
64
66
  context 'deletes_for' do
65
67
  before do
66
68
  receiver.catch search_request(2, verb: :delete), DummiesIndex::Fizz
67
- receiver.catch search_request(3, verb: :delete), DummiesIndex::Buzz
69
+ receiver.catch search_request(3, verb: :delete), Dummies2Index::Buzz
68
70
  end
69
71
 
70
72
  specify 'returns deletes for a specific type' do
71
- expect(receiver.deletes_for(DummiesIndex::Buzz)).to match_array([1, 2, 3])
73
+ expect(receiver.deletes_for(Dummies2Index::Buzz)).to match_array([1, 2, 3])
72
74
  end
73
75
 
74
76
  specify 'returns only deletes for all types' do
75
77
  deletes = receiver.deletes
76
- expect(deletes.keys).to match_array([DummiesIndex::Fizz, DummiesIndex::Buzz])
78
+ expect(deletes.keys).to match_array([DummiesIndex::Fizz, Dummies2Index::Buzz])
77
79
  expect(deletes.values.flatten).to match_array([1, 2, 1, 2, 3])
78
80
  end
79
81
  end
@@ -113,8 +115,8 @@ describe :search_index_receiver do
113
115
  context 'updated_indexes' do
114
116
  specify 'provides a list of indices updated' do
115
117
  receiver.catch search_request(2, verb: :delete), DummiesIndex::Fizz
116
- receiver.catch search_request(3, verb: :delete), DummiesIndex::Buzz
117
- expect(receiver.updated_indexes).to match_array([DummiesIndex::Fizz, DummiesIndex::Buzz])
118
+ receiver.catch search_request(3, verb: :delete), Dummies2Index::Buzz
119
+ expect(receiver.updated_indexes).to match_array([DummiesIndex::Fizz, Dummies2Index::Buzz])
118
120
  end
119
121
  end
120
122
  end