chewy 7.6.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +1 -1
  3. data/.github/dependabot.yml +2 -2
  4. data/.github/workflows/ruby.yml +11 -10
  5. data/.rubocop.yml +1 -1
  6. data/.rubocop_todo.yml +132 -39
  7. data/CHANGELOG.md +18 -1
  8. data/CONTRIBUTING.md +1 -1
  9. data/LICENSE.txt +1 -1
  10. data/README.md +50 -1125
  11. data/chewy.gemspec +3 -2
  12. data/docker-compose.yml +14 -0
  13. data/docs/README.md +16 -0
  14. data/docs/configuration.md +440 -0
  15. data/docs/import.md +122 -0
  16. data/docs/indexing.md +329 -0
  17. data/docs/querying.md +72 -0
  18. data/docs/rake_tasks.md +108 -0
  19. data/docs/testing.md +41 -0
  20. data/docs/troubleshooting.md +101 -0
  21. data/gemfiles/base.gemfile +3 -3
  22. data/gemfiles/{rails.6.1.activerecord.gemfile → rails.7.2.activerecord.gemfile} +3 -3
  23. data/gemfiles/{rails.7.0.activerecord.gemfile → rails.8.0.activerecord.gemfile} +3 -3
  24. data/lib/chewy/config.rb +2 -2
  25. data/lib/chewy/errors.rb +3 -0
  26. data/lib/chewy/fields/root.rb +1 -1
  27. data/lib/chewy/index/actions.rb +5 -5
  28. data/lib/chewy/index/aliases.rb +1 -1
  29. data/lib/chewy/index/syncer.rb +5 -5
  30. data/lib/chewy/minitest/helpers.rb +1 -1
  31. data/lib/chewy/search/request.rb +4 -4
  32. data/lib/chewy/search/response.rb +7 -0
  33. data/lib/chewy/search/scrolling.rb +2 -1
  34. data/lib/chewy/strategy/delayed_sidekiq/worker.rb +1 -1
  35. data/lib/chewy/version.rb +1 -1
  36. data/lib/chewy.rb +4 -0
  37. data/migration_guide.md +1 -1
  38. data/spec/chewy/config_spec.rb +13 -14
  39. data/spec/chewy/elastic_client_spec.rb +1 -1
  40. data/spec/chewy/fields/base_spec.rb +2 -2
  41. data/spec/chewy/fields/time_fields_spec.rb +1 -1
  42. data/spec/chewy/index/actions_spec.rb +9 -70
  43. data/spec/chewy/index/aliases_spec.rb +1 -1
  44. data/spec/chewy/index/import/bulk_builder_spec.rb +2 -2
  45. data/spec/chewy/index/import/bulk_request_spec.rb +1 -1
  46. data/spec/chewy/index/import/routine_spec.rb +1 -1
  47. data/spec/chewy/index/import_spec.rb +15 -15
  48. data/spec/chewy/index/observe/callback_spec.rb +1 -1
  49. data/spec/chewy/index/specification_spec.rb +1 -4
  50. data/spec/chewy/index/syncer_spec.rb +1 -1
  51. data/spec/chewy/index_spec.rb +1 -1
  52. data/spec/chewy/journal_spec.rb +2 -2
  53. data/spec/chewy/minitest/helpers_spec.rb +2 -6
  54. data/spec/chewy/multi_search_spec.rb +1 -1
  55. data/spec/chewy/rake_helper_spec.rb +1 -1
  56. data/spec/chewy/repository_spec.rb +4 -4
  57. data/spec/chewy/rspec/update_index_spec.rb +2 -2
  58. data/spec/chewy/runtime_spec.rb +2 -2
  59. data/spec/chewy/search/loader_spec.rb +1 -1
  60. data/spec/chewy/search/pagination/kaminari_examples.rb +1 -1
  61. data/spec/chewy/search/query_proxy_spec.rb +0 -24
  62. data/spec/chewy/search/request_spec.rb +7 -3
  63. data/spec/chewy/search/response_spec.rb +2 -24
  64. data/spec/chewy/search/scrolling_spec.rb +1 -1
  65. data/spec/chewy/search_spec.rb +1 -1
  66. data/spec/chewy/stash_spec.rb +1 -1
  67. data/spec/chewy/strategy/delayed_sidekiq_spec.rb +27 -10
  68. data/spec/chewy/strategy_spec.rb +1 -1
  69. data/spec/chewy_spec.rb +5 -22
  70. data/spec/spec_helper.rb +26 -0
  71. data/spec/support/active_record.rb +35 -4
  72. metadata +22 -17
  73. data/gemfiles/rails.7.1.activerecord.gemfile +0 -14
@@ -1,8 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'activejob', '~> 7.0.0'
4
- gem 'activerecord', '~> 7.0.0'
5
- gem 'activesupport', '~> 7.0.0'
3
+ gem 'activejob', '~> 8.0.0'
4
+ gem 'activerecord', '~> 8.0.0'
5
+ gem 'activesupport', '~> 8.0.0'
6
6
  gem 'kaminari-core', '~> 1.1.0', require: false
7
7
  gem 'parallel', require: false
8
8
  gem 'rspec_junit_formatter', '~> 0.4.1'
data/lib/chewy/config.rb CHANGED
@@ -70,12 +70,12 @@ module Chewy
70
70
  end
71
71
 
72
72
  def transport_logger=(logger)
73
- Chewy.client.transport.transport.logger = logger
73
+ Chewy.client.transport.logger = logger
74
74
  @transport_logger = logger
75
75
  end
76
76
 
77
77
  def transport_tracer=(tracer)
78
- Chewy.client.transport.transport.tracer = tracer
78
+ Chewy.client.transport.tracer = tracer
79
79
  @transport_tracer = tracer
80
80
  end
81
81
 
data/lib/chewy/errors.rb CHANGED
@@ -39,4 +39,7 @@ module Chewy
39
39
 
40
40
  class ImportScopeCleanupError < Error
41
41
  end
42
+
43
+ class FeatureDisabled < Error
44
+ end
42
45
  end
@@ -4,7 +4,7 @@ module Chewy
4
4
  attr_reader :dynamic_templates, :id
5
5
 
6
6
  def initialize(name, **options)
7
- super(name, **options)
7
+ super
8
8
 
9
9
  @value ||= -> { self }
10
10
  @dynamic_templates = []
@@ -32,7 +32,7 @@ module Chewy
32
32
  #
33
33
  def create(*args, **kwargs)
34
34
  create!(*args, **kwargs)
35
- rescue Elasticsearch::Transport::Transport::Errors::BadRequest
35
+ rescue Elastic::Transport::Transport::Errors::BadRequest
36
36
  false
37
37
  end
38
38
 
@@ -83,9 +83,9 @@ module Chewy
83
83
  result = client.indices.delete index: index_names.join(',')
84
84
  Chewy.wait_for_status if result
85
85
  result
86
- # es-ruby >= 1.0.10 handles Elasticsearch::Transport::Transport::Errors::NotFound
86
+ # es-ruby >= 1.0.10 handles Elastic::Transport::Transport::Errors::NotFound
87
87
  # by itself, rescue is for previous versions
88
- rescue Elasticsearch::Transport::Transport::Errors::NotFound
88
+ rescue Elastic::Transport::Transport::Errors::NotFound
89
89
  false
90
90
  end
91
91
 
@@ -99,9 +99,9 @@ module Chewy
99
99
  # UsersIndex.delete '01-2014' # deletes `users_01-2014` index
100
100
  #
101
101
  def delete!(suffix = nil)
102
- # es-ruby >= 1.0.10 handles Elasticsearch::Transport::Transport::Errors::NotFound
102
+ # es-ruby >= 1.0.10 handles Elastic::Transport::Transport::Errors::NotFound
103
103
  # by itself, so it is raised here
104
- delete(suffix) or raise Elasticsearch::Transport::Transport::Errors::NotFound
104
+ delete(suffix) or raise Elastic::Transport::Transport::Errors::NotFound
105
105
  end
106
106
 
107
107
  # Deletes and recreates index. Supports suffixes.
@@ -22,7 +22,7 @@ module Chewy
22
22
 
23
23
  def empty_if_not_found
24
24
  yield
25
- rescue Elasticsearch::Transport::Transport::Errors::NotFound
25
+ rescue Elastic::Transport::Transport::Errors::NotFound
26
26
  []
27
27
  end
28
28
  end
@@ -157,8 +157,8 @@ module Chewy
157
157
  batch_size: DEFAULT_SYNC_BATCH_SIZE,
158
158
  typecast: false
159
159
  }
160
- @index.adapter.import_fields(import_fields_args).to_a.flatten(1).each do |data|
161
- data[0] = data[0].to_s
160
+ @index.adapter.import_fields(import_fields_args).to_a.flatten(1).map do |data|
161
+ [data[0].to_s, *data[1..]]
162
162
  end
163
163
  else
164
164
  @index.adapter.import_fields(batch_size: DEFAULT_SYNC_BATCH_SIZE, typecast: false).to_a.flatten(1).map(&:to_s)
@@ -167,8 +167,8 @@ module Chewy
167
167
 
168
168
  def fetch_index_data
169
169
  if @index.supports_outdated_sync?
170
- @index.pluck(:_id, @index.outdated_sync_field).each do |data|
171
- data[0] = data[0].to_s
170
+ @index.pluck(:_id, @index.outdated_sync_field).map do |data|
171
+ [data[0].to_s, *data[1..]]
172
172
  end
173
173
  else
174
174
  @index.pluck(:_id).map(&:to_s)
@@ -213,7 +213,7 @@ module Chewy
213
213
  @outdated_sync_field_type = mappings
214
214
  .fetch('properties', {})
215
215
  .fetch(@index.outdated_sync_field.to_s, {})['type']
216
- rescue Elasticsearch::Transport::Transport::Errors::NotFound
216
+ rescue Elastic::Transport::Transport::Errors::NotFound
217
217
  nil
218
218
  end
219
219
  end
@@ -142,7 +142,7 @@ module Chewy
142
142
  teardown do
143
143
  # always destroy indexes between tests
144
144
  # Prevent croll pollution of test cases due to indexing
145
- Chewy.massacre
145
+ drop_indices
146
146
  end
147
147
  end
148
148
  end
@@ -46,7 +46,7 @@ module Chewy
46
46
 
47
47
  delegate :hits, :wrappers, :objects, :records, :documents,
48
48
  :object_hash, :record_hash, :document_hash,
49
- :total, :max_score, :took, :timed_out?, to: :response
49
+ :total, :max_score, :took, :timed_out?, :terminated_early?, to: :response
50
50
  delegate :each, :size, :to_a, :[], to: :wrappers
51
51
  alias_method :to_ary, :to_a
52
52
  alias_method :total_count, :total
@@ -854,7 +854,7 @@ module Chewy
854
854
  else
855
855
  Chewy.client.count(only(WHERE_STORAGES).render)['count']
856
856
  end
857
- rescue Elasticsearch::Transport::Transport::Errors::NotFound
857
+ rescue Elastic::Transport::Transport::Errors::NotFound
858
858
  0
859
859
  end
860
860
 
@@ -891,7 +891,7 @@ module Chewy
891
891
  def first(limit = UNDEFINED)
892
892
  request_limit = limit == UNDEFINED ? 1 : limit
893
893
 
894
- if performed? && (request_limit <= size || size == total)
894
+ if performed? && (terminated_early? || request_limit <= size || size == total)
895
895
  limit == UNDEFINED ? wrappers.first : wrappers.first(limit)
896
896
  else
897
897
  result = except(EXTRA_STORAGES).limit(request_limit).to_a
@@ -1035,7 +1035,7 @@ module Chewy
1035
1035
  request_body = render.merge(additional)
1036
1036
  ActiveSupport::Notifications.instrument 'search_query.chewy', notification_payload(request: request_body) do
1037
1037
  Chewy.client.search(request_body)
1038
- rescue Elasticsearch::Transport::Transport::Errors::NotFound
1038
+ rescue Elastic::Transport::Transport::Errors::NotFound
1039
1039
  {}
1040
1040
  end
1041
1041
  end
@@ -47,6 +47,13 @@ module Chewy
47
47
  @timed_out ||= @body['timed_out']
48
48
  end
49
49
 
50
+ # Has the request been terminated early?
51
+ #
52
+ # @return [true, false]
53
+ def terminated_early?
54
+ @terminated_early ||= @body['terminated_early']
55
+ end
56
+
50
57
  # The `suggest` response part. Returns empty hash if suggests
51
58
  # were not requested.
52
59
  #
@@ -39,7 +39,8 @@ module Chewy
39
39
  hits = hits.first(last_batch_size) if last_batch_size != 0 && fetched >= total
40
40
  yield(hits) if hits.present?
41
41
  scroll_id = result['_scroll_id']
42
- break if fetched >= total
42
+
43
+ break if result['terminated_early'] || fetched >= total
43
44
 
44
45
  result = perform_scroll(scroll: scroll, scroll_id: scroll_id)
45
46
  end
@@ -68,7 +68,7 @@ module Chewy
68
68
 
69
69
  fields = nil if fields.include?(Scheduler::FALLBACK_FIELDS)
70
70
 
71
- [ids.map(&:to_i), fields]
71
+ [ids, fields]
72
72
  end
73
73
  end
74
74
  end
data/lib/chewy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Chewy
2
- VERSION = '7.6.0'.freeze
2
+ VERSION = '8.0.0'.freeze
3
3
  end
data/lib/chewy.rb CHANGED
@@ -116,6 +116,10 @@ module Chewy
116
116
  # Be careful, if current prefix is blank, this will destroy all the indexes.
117
117
  #
118
118
  def massacre
119
+ unless Chewy.settings[:delete_all_enabled]
120
+ raise FeatureDisabled, 'Feature disabled by default in ES 8. You can enable it in the cluster and set `delete_all_enabled` option in settings'
121
+ end
122
+
119
123
  Chewy.client.indices.delete(index: [Chewy.configuration[:prefix], '*'].reject(&:blank?).join('_'))
120
124
  Chewy.wait_for_status
121
125
  end
data/migration_guide.md CHANGED
@@ -23,7 +23,7 @@ In order to upgrade Chewy 6/Elasticsearch 6 to Chewy 7/Elasticsearch 7 in the mo
23
23
  * Run manual tests on Chewy 7.1 / Elasticsearch 7
24
24
  * Upgrade to Chewy 7.1
25
25
  * Upgrade to Chewy 7.2:
26
- * Remove all the the `Chewy::Type` class usages, e.g. remove `CitiesIndex::City` / `CitiesIndex.city`
26
+ * Remove all the `Chewy::Type` class usages, e.g. remove `CitiesIndex::City` / `CitiesIndex.city`
27
27
  * `CitiesIndex::City.import! ...` becomes `CitiesIndex.import! ...`
28
28
  * Update indexes with simplified DSL:
29
29
  * `define_type` block -> `index_scope` clause
@@ -3,18 +3,17 @@ require 'spec_helper'
3
3
  describe Chewy::Config do
4
4
  subject { described_class.send(:new) }
5
5
 
6
- its(:logger) { should be_nil }
7
- its(:transport_logger) { should be_nil }
8
- its(:transport_logger) { should be_nil }
9
- its(:root_strategy) { should == :base }
10
- its(:request_strategy) { should == :atomic }
11
- its(:console_strategy) { should == :urgent }
12
- its(:use_after_commit_callbacks) { should == true }
13
- its(:indices_path) { should == 'app/chewy' }
14
- its(:reset_disable_refresh_interval) { should == false }
15
- its(:reset_no_replicas) { should == false }
16
- its(:disable_refresh_async) { should == false }
17
- its(:search_class) { should be < Chewy::Search::Request }
6
+ specify { expect(subject.logger).to be_nil }
7
+ specify { expect(subject.transport_logger).to be_nil }
8
+ specify { expect(subject.root_strategy).to eq(:base) }
9
+ specify { expect(subject.request_strategy).to eq(:atomic) }
10
+ specify { expect(subject.console_strategy).to eq(:urgent) }
11
+ specify { expect(subject.use_after_commit_callbacks).to eq(true) }
12
+ specify { expect(subject.indices_path).to eq('app/chewy') }
13
+ specify { expect(subject.reset_disable_refresh_interval).to eq(false) }
14
+ specify { expect(subject.reset_no_replicas).to eq(false) }
15
+ specify { expect(subject.disable_refresh_async).to eq(false) }
16
+ specify { expect(subject.search_class).to be < Chewy::Search::Request }
18
17
 
19
18
  describe '#transport_logger=' do
20
19
  let(:logger) { Logger.new('/dev/null') }
@@ -22,7 +21,7 @@ describe Chewy::Config do
22
21
 
23
22
  specify do
24
23
  expect { subject.transport_logger = logger }
25
- .to change { Chewy.client.transport.transport.logger }.to(logger)
24
+ .to change { Chewy.client.transport.logger }.to(logger)
26
25
  end
27
26
  specify do
28
27
  expect { subject.transport_logger = logger }
@@ -40,7 +39,7 @@ describe Chewy::Config do
40
39
 
41
40
  specify do
42
41
  expect { subject.transport_tracer = tracer }
43
- .to change { Chewy.client.transport.transport.tracer }.to(tracer)
42
+ .to change { Chewy.client.transport.tracer }.to(tracer)
44
43
  end
45
44
  specify do
46
45
  expect { subject.transport_tracer = tracer }
@@ -6,7 +6,7 @@ describe Chewy::ElasticClient do
6
6
  let!(:filter_previous_value) { Chewy.before_es_request_filter }
7
7
 
8
8
  before do
9
- Chewy.massacre
9
+ drop_indices
10
10
  stub_index(:products) do
11
11
  field :id, type: :integer
12
12
  end
@@ -5,7 +5,7 @@ describe Chewy::Fields::Base do
5
5
  specify { expect(described_class.new('name', type: 'integer').options[:type]).to eq('integer') }
6
6
 
7
7
  describe '#compose' do
8
- let(:field) { described_class.new(:name, value: ->(o) { o.value }) }
8
+ let(:field) { described_class.new(:name, value: lambda(&:value)) }
9
9
 
10
10
  specify { expect(field.compose(double(value: 'hello'))).to eq(name: 'hello') }
11
11
  specify { expect(field.compose(double(value: %w[hello world]))).to eq(name: %w[hello world]) }
@@ -23,7 +23,7 @@ describe Chewy::Fields::Base do
23
23
 
24
24
  context 'nested fields' do
25
25
  before do
26
- field.children.push(described_class.new(:subname1, value: ->(o) { o.subvalue1 }))
26
+ field.children.push(described_class.new(:subname1, value: lambda(&:subvalue1)))
27
27
  field.children.push(described_class.new(:subname2, value: -> { subvalue2 }))
28
28
  field.children.push(described_class.new(:subname3))
29
29
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'Time fields' do
4
- before { Chewy.massacre }
4
+ before { drop_indices }
5
5
 
6
6
  before do
7
7
  stub_index(:posts) do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Chewy::Index::Actions do
4
- before { Chewy.massacre }
4
+ before { drop_indices }
5
5
 
6
6
  before do
7
7
  stub_index :dummies
@@ -78,12 +78,12 @@ describe Chewy::Index::Actions do
78
78
  specify do
79
79
  expect do
80
80
  DummiesIndex.create!
81
- end.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/already exists.*dummies/)
81
+ end.to raise_error(Elastic::Transport::Transport::Errors::BadRequest).with_message(/already exists.*dummies/)
82
82
  end
83
83
  specify do
84
84
  expect do
85
85
  DummiesIndex.create!('2013')
86
- end.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/Invalid alias name \[dummies\]/)
86
+ end.to raise_error(Elastic::Transport::Transport::Errors::BadRequest).with_message(/Invalid alias name \[dummies\]/)
87
87
  end
88
88
  end
89
89
 
@@ -100,7 +100,7 @@ describe Chewy::Index::Actions do
100
100
  specify do
101
101
  expect do
102
102
  DummiesIndex.create!('2013')
103
- end.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/already exists.*dummies_2013/)
103
+ end.to raise_error(Elastic::Transport::Transport::Errors::BadRequest).with_message(/already exists.*dummies_2013/)
104
104
  end
105
105
  specify { expect(DummiesIndex.create!('2014')['acknowledged']).to eq(true) }
106
106
 
@@ -190,11 +190,11 @@ describe Chewy::Index::Actions do
190
190
  end
191
191
 
192
192
  describe '.delete!' do
193
- specify { expect { DummiesIndex.delete! }.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound) }
193
+ specify { expect { DummiesIndex.delete! }.to raise_error(Elastic::Transport::Transport::Errors::NotFound) }
194
194
  specify do
195
195
  expect do
196
196
  DummiesIndex.delete!('2013')
197
- end.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
197
+ end.to raise_error(Elastic::Transport::Transport::Errors::NotFound)
198
198
  end
199
199
 
200
200
  context do
@@ -583,67 +583,6 @@ describe Chewy::Index::Actions do
583
583
  end
584
584
  end
585
585
 
586
- xcontext 'applying journal' do
587
- before do
588
- stub_index(:cities) do
589
- index_scope City
590
- field :name, value: (lambda do
591
- sleep(rating)
592
- name
593
- end)
594
- end
595
- end
596
-
597
- let!(:cities) { Array.new(3) { |i| City.create!(id: i + 1, name: "Name#{i + 1}", rating: 1) } }
598
-
599
- let(:parallel_update) do
600
- Thread.new do
601
- p 'start parallel'
602
- sleep(1.5)
603
- cities.first.update(name: 'NewName1', rating: 0)
604
- cities.last.update(name: 'NewName3', rating: 0)
605
- CitiesIndex::City.import!([cities.first, cities.last], journal: true)
606
- p 'end parallel'
607
- end
608
- end
609
-
610
- specify 'with journal application' do
611
- cities
612
- p 'cities created1'
613
- ActiveRecord::Base.connection.close if defined?(ActiveRecord::Base)
614
- [
615
- parallel_update,
616
- Thread.new do
617
- p 'start reset1'
618
- CitiesIndex.reset!('suffix')
619
- p 'end reset1'
620
- end
621
- ].map(&:join)
622
- ActiveRecord::Base.connection.reconnect! if defined?(ActiveRecord::Base)
623
- p 'expect1'
624
- expect(CitiesIndex::City.pluck(:_id, :name)).to contain_exactly(%w[1 NewName1], %w[2 Name2], %w[3 NewName3])
625
- p 'end expect1'
626
- end
627
-
628
- specify 'without journal application' do
629
- cities
630
- p 'cities created2'
631
- ActiveRecord::Base.connection.close if defined?(ActiveRecord::Base)
632
- [
633
- parallel_update,
634
- Thread.new do
635
- p 'start reset2'
636
- CitiesIndex.reset!('suffix', apply_journal: false)
637
- p 'end reset2'
638
- end
639
- ].map(&:join)
640
- ActiveRecord::Base.connection.reconnect! if defined?(ActiveRecord::Base)
641
- p 'expect2'
642
- expect(CitiesIndex::City.pluck(:_id, :name)).to contain_exactly(%w[1 Name1], %w[2 Name2], %w[3 Name3])
643
- p 'end expect2'
644
- end
645
- end
646
-
647
586
  context 'journaling' do
648
587
  before { City.create!(id: 1, name: 'Moscow') }
649
588
 
@@ -768,7 +707,7 @@ describe Chewy::Index::Actions do
768
707
  .to receive(:clear_cache)
769
708
  .and_call_original
770
709
  expect { CitiesIndex.clear_cache({index: unexisted_index_name}) }
771
- .to raise_error Elasticsearch::Transport::Transport::Errors::NotFound
710
+ .to raise_error Elastic::Transport::Transport::Errors::NotFound
772
711
  end
773
712
  end
774
713
 
@@ -820,7 +759,7 @@ describe Chewy::Index::Actions do
820
759
  .to receive(:reindex)
821
760
  .and_call_original
822
761
  expect { CitiesIndex.reindex(source: unexisting_index, dest: dest_index_with_prefix) }
823
- .to raise_error Elasticsearch::Transport::Transport::Errors::NotFound
762
+ .to raise_error Elastic::Transport::Transport::Errors::NotFound
824
763
  end
825
764
  end
826
765
 
@@ -883,7 +822,7 @@ describe Chewy::Index::Actions do
883
822
  context 'index name' do
884
823
  specify do
885
824
  expect { CitiesIndex.update_mapping(unexisting_index, body_hash) }
886
- .to raise_error Elasticsearch::Transport::Transport::Errors::NotFound
825
+ .to raise_error Elastic::Transport::Transport::Errors::NotFound
887
826
  end
888
827
  end
889
828
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Chewy::Index::Aliases do
4
- before { Chewy.massacre }
4
+ before { drop_indices }
5
5
 
6
6
  before { stub_index :dummies }
7
7
 
@@ -17,7 +17,7 @@ SimpleComment = Class.new do
17
17
  end
18
18
 
19
19
  describe Chewy::Index::Import::BulkBuilder do
20
- before { Chewy.massacre }
20
+ before { drop_indices }
21
21
 
22
22
  subject { described_class.new(index, to_index: to_index, delete: delete, fields: fields) }
23
23
  let(:index) { CitiesIndex }
@@ -216,7 +216,7 @@ describe Chewy::Index::Import::BulkBuilder do
216
216
  end
217
217
 
218
218
  def do_raw_index_comment(options:, data:)
219
- CommentsIndex.client.index(options.merge(index: 'comments', type: '_doc', refresh: true, body: data))
219
+ CommentsIndex.client.index(options.merge(index: 'comments', refresh: true, body: data))
220
220
  end
221
221
 
222
222
  def raw_index_comment(comment)
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Chewy::Index::Import::BulkRequest do
4
- before { Chewy.massacre }
4
+ before { drop_indices }
5
5
 
6
6
  subject { described_class.new(index, suffix: suffix, bulk_size: bulk_size, **bulk_options) }
7
7
  let(:suffix) {}
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  # TODO: add more specs here later
4
4
  describe Chewy::Index::Import::Routine do
5
- before { Chewy.massacre }
5
+ before { drop_indices }
6
6
  before do
7
7
  stub_index(:cities) do
8
8
  field :name
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Chewy::Index::Import do
4
- before { Chewy.massacre }
4
+ before { drop_indices }
5
5
 
6
6
  before do
7
7
  stub_model(:city)
@@ -204,10 +204,10 @@ describe Chewy::Index::Import do
204
204
  end
205
205
  end
206
206
 
207
- let(:mapper_parsing_exception) do
207
+ let(:document_parsing_exception) do
208
208
  {
209
- 'type' => 'mapper_parsing_exception',
210
- 'reason' => 'object mapping for [name] tried to parse field [name] as object, but found a concrete value'
209
+ 'type' => 'document_parsing_exception',
210
+ 'reason' => '[1:9] object mapping for [name] tried to parse field [name] as object, but found a concrete value'
211
211
  }
212
212
  end
213
213
 
@@ -215,7 +215,7 @@ describe Chewy::Index::Import do
215
215
  payload = subscribe_notification
216
216
  import dummy_cities, batch_size: 2
217
217
  expect(payload).to eq(index: CitiesIndex,
218
- errors: {index: {mapper_parsing_exception => %w[1 2 3]}},
218
+ errors: {index: {document_parsing_exception => %w[1 2 3]}},
219
219
  import: {index: 3})
220
220
  end
221
221
  end
@@ -270,8 +270,8 @@ describe Chewy::Index::Import do
270
270
  expect(payload).to eq(
271
271
  errors: {
272
272
  index: {{
273
- 'type' => 'mapper_parsing_exception',
274
- 'reason' => 'object mapping for [object] tried to parse field [object] as object, but found a concrete value'
273
+ 'type' => 'document_parsing_exception',
274
+ 'reason' => '[1:27] object mapping for [object] tried to parse field [object] as object, but found a concrete value'
275
275
  } => %w[2 4]}
276
276
  },
277
277
  import: {index: 6},
@@ -293,8 +293,8 @@ describe Chewy::Index::Import do
293
293
  expect(payload).to eq(
294
294
  errors: {
295
295
  index: {{
296
- 'type' => 'mapper_parsing_exception',
297
- 'reason' => 'object mapping for [object] tried to parse field [object] as object, but found a concrete value'
296
+ 'type' => 'document_parsing_exception',
297
+ 'reason' => '[1:27] object mapping for [object] tried to parse field [object] as object, but found a concrete value'
298
298
  } => %w[2 4]}
299
299
  },
300
300
  import: {index: 6},
@@ -319,8 +319,8 @@ describe Chewy::Index::Import do
319
319
  expect(payload).to eq(
320
320
  errors: {
321
321
  index: {{
322
- 'type' => 'mapper_parsing_exception',
323
- 'reason' => 'object mapping for [object] tried to parse field [object] as object, but found a concrete value'
322
+ 'type' => 'document_parsing_exception',
323
+ 'reason' => '[1:27] object mapping for [object] tried to parse field [object] as object, but found a concrete value'
324
324
  } => %w[2 4]}
325
325
  },
326
326
  import: {index: 6},
@@ -383,8 +383,8 @@ describe Chewy::Index::Import do
383
383
 
384
384
  # Full match doesn't work here.
385
385
  expect(payload[:errors][:update].keys).to match([
386
- hash_including('type' => 'document_missing_exception', 'reason' => '[_doc][1]: document missing'),
387
- hash_including('type' => 'document_missing_exception', 'reason' => '[_doc][3]: document missing')
386
+ hash_including('type' => 'document_missing_exception', 'reason' => '[1]: document missing'),
387
+ hash_including('type' => 'document_missing_exception', 'reason' => '[3]: document missing')
388
388
  ])
389
389
  expect(payload[:errors][:update].values).to eq([['1'], ['3']])
390
390
  expect(imported_cities).to match_array([
@@ -431,8 +431,8 @@ describe Chewy::Index::Import do
431
431
  expect(payload).to eq(
432
432
  errors: {
433
433
  update: {{
434
- 'type' => 'mapper_parsing_exception',
435
- 'reason' => 'object mapping for [object] tried to parse field [object] as object, but found a concrete value'
434
+ 'type' => 'document_parsing_exception',
435
+ 'reason' => '[1:26] object mapping for [object] tried to parse field [object] as object, but found a concrete value'
436
436
  } => %w[2 4]}
437
437
  },
438
438
  import: {index: 6},
@@ -21,7 +21,7 @@ describe Chewy::Index::Observe::Callback do
21
21
  end
22
22
 
23
23
  context 'when executable is has arity 1' do
24
- let(:executable) { ->(record) { record.population } }
24
+ let(:executable) { lambda(&:population) }
25
25
 
26
26
  it 'calls exectuable within context' do
27
27
  expect(callback.call(city)).to eq(city.population)
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Chewy::Index::Specification do
4
- before { Chewy.massacre }
4
+ before { drop_indices }
5
5
 
6
6
  let(:index1) do
7
7
  stub_index(:places) do
@@ -46,7 +46,6 @@ describe Chewy::Index::Specification do
46
46
  specify do
47
47
  expect { specification1.lock! }.to change { Chewy::Stash::Specification.all.hits }.from([]).to([{
48
48
  '_index' => 'chewy_specifications',
49
- '_type' => '_doc',
50
49
  '_id' => 'places',
51
50
  '_score' => 1.0,
52
51
  '_source' => {'specification' => Base64.encode64({
@@ -62,7 +61,6 @@ describe Chewy::Index::Specification do
62
61
  specify do
63
62
  expect { specification5.lock! }.to change { Chewy::Stash::Specification.all.hits }.to([{
64
63
  '_index' => 'chewy_specifications',
65
- '_type' => '_doc',
66
64
  '_id' => 'places',
67
65
  '_score' => 1.0,
68
66
  '_source' => {'specification' => Base64.encode64({
@@ -71,7 +69,6 @@ describe Chewy::Index::Specification do
71
69
  }.to_json)}
72
70
  }, {
73
71
  '_index' => 'chewy_specifications',
74
- '_type' => '_doc',
75
72
  '_id' => 'namespace/cities',
76
73
  '_score' => 1.0,
77
74
  '_source' => {'specification' => Base64.encode64({
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Chewy::Index::Syncer, :orm do
4
- before { Chewy.massacre }
4
+ before { drop_indices }
5
5
  before do
6
6
  stub_model(:city)
7
7
  stub_index(:cities) do
@@ -177,7 +177,7 @@ describe Chewy::Index do
177
177
 
178
178
  context do
179
179
  before do
180
- Chewy.massacre
180
+ drop_indices
181
181
  PlacesIndex.import!(
182
182
  double(colors: ['red']),
183
183
  double(colors: %w[red green]),