chewy 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/CHANGELOG.md +24 -0
- data/Guardfile +1 -2
- data/README.md +23 -4
- data/chewy.gemspec +3 -1
- data/lib/chewy.rb +1 -0
- data/lib/chewy/fields/base.rb +1 -1
- data/lib/chewy/fields/root.rb +13 -0
- data/lib/chewy/index/search.rb +1 -1
- data/lib/chewy/query.rb +247 -8
- data/lib/chewy/query/criteria.rb +33 -1
- data/lib/chewy/railtie.rb +5 -0
- data/lib/chewy/rspec/update_index.rb +16 -9
- data/lib/chewy/type/actions.rb +19 -0
- data/lib/chewy/type/adapter/active_record.rb +1 -1
- data/lib/chewy/type/base.rb +2 -0
- data/lib/chewy/type/import.rb +44 -8
- data/lib/chewy/version.rb +1 -1
- data/lib/generators/chewy/install_generator.rb +11 -0
- data/lib/generators/templates/chewy.yml +7 -0
- data/lib/tasks/chewy.rake +1 -1
- data/spec/chewy/config_spec.rb +3 -3
- data/spec/chewy/index/actions_spec.rb +53 -53
- data/spec/chewy/query/criteria_spec.rb +58 -10
- data/spec/chewy/query_spec.rb +102 -2
- data/spec/chewy/runtime_spec.rb +1 -1
- data/spec/chewy/type/actions_spec.rb +28 -0
- data/spec/chewy/type/adapter/active_record_spec.rb +29 -28
- data/spec/chewy/type/adapter/object_spec.rb +9 -9
- data/spec/chewy/type/import_spec.rb +87 -10
- data/spec/chewy/type/mapping_spec.rb +30 -0
- data/spec/spec_helper.rb +2 -1
- metadata +37 -4
data/lib/chewy/query/criteria.rb
CHANGED
@@ -4,7 +4,7 @@ module Chewy
|
|
4
4
|
class Query
|
5
5
|
class Criteria
|
6
6
|
include Compose
|
7
|
-
ARRAY_STORAGES = [:queries, :filters, :post_filters, :sort, :fields, :types]
|
7
|
+
ARRAY_STORAGES = [:queries, :filters, :post_filters, :sort, :fields, :types, :scores]
|
8
8
|
HASH_STORAGES = [:options, :request_options, :facets, :aggregations, :suggest]
|
9
9
|
STORAGES = ARRAY_STORAGES + HASH_STORAGES
|
10
10
|
|
@@ -52,6 +52,10 @@ module Chewy
|
|
52
52
|
facets.merge!(modifer)
|
53
53
|
end
|
54
54
|
|
55
|
+
def update_scores(modifer)
|
56
|
+
@scores = scores + Array.wrap(modifer).reject(&:blank?)
|
57
|
+
end
|
58
|
+
|
55
59
|
def update_aggregations(modifer)
|
56
60
|
aggregations.merge!(modifer)
|
57
61
|
end
|
@@ -99,6 +103,7 @@ module Chewy
|
|
99
103
|
def request_body
|
100
104
|
body = {}
|
101
105
|
|
106
|
+
|
102
107
|
body.merge!(_filtered_query(_request_query, _request_filter, options.slice(:strategy)))
|
103
108
|
body.merge!(post_filter: _request_post_filter) if post_filters?
|
104
109
|
body.merge!(facets: facets) if facets?
|
@@ -107,9 +112,15 @@ module Chewy
|
|
107
112
|
body.merge!(sort: sort) if sort?
|
108
113
|
body.merge!(_source: fields) if fields?
|
109
114
|
|
115
|
+
body = _boost_query(body)
|
116
|
+
|
110
117
|
{ body: body.merge!(request_options) }
|
111
118
|
end
|
112
119
|
|
120
|
+
def delete_all_request_body
|
121
|
+
{ body: _filtered_query(_request_query, _request_filter, options.slice(:strategy)).presence || { query: { match_all: {} } } }
|
122
|
+
end
|
123
|
+
|
113
124
|
protected
|
114
125
|
|
115
126
|
def storages
|
@@ -123,6 +134,27 @@ module Chewy
|
|
123
134
|
end
|
124
135
|
end
|
125
136
|
|
137
|
+
def _boost_query(body)
|
138
|
+
scores? or return body
|
139
|
+
query = body.delete :query
|
140
|
+
filter = body.delete :filter
|
141
|
+
if query && filter
|
142
|
+
query = { filtered: { query: query, filter: filter } }
|
143
|
+
filter = nil
|
144
|
+
end
|
145
|
+
score = { }
|
146
|
+
score[:functions] = scores
|
147
|
+
score[:boost_mode] = options[:boost_mode] if options[:boost_mode]
|
148
|
+
score[:score_mode] = options[:score_mode] if options[:score_mode]
|
149
|
+
score[:query] = query if query
|
150
|
+
score[:filter] = filter if filter
|
151
|
+
body.tap { |b| b[:query] = { function_score: score } }
|
152
|
+
end
|
153
|
+
|
154
|
+
def _request_options
|
155
|
+
options.slice(:size, :from, :explain, :highlight, :rescore)
|
156
|
+
end
|
157
|
+
|
126
158
|
def _request_query
|
127
159
|
_queries_join(queries, options[:query_mode])
|
128
160
|
end
|
data/lib/chewy/railtie.rb
CHANGED
@@ -18,6 +18,11 @@ module Chewy
|
|
18
18
|
duration = ((finish - start).to_f * 10000).round / 10.0
|
19
19
|
Rails.logger.debug(" \e[1m\e[32m#{payload[:index]} Search (#{duration}ms)\e[0m #{payload[:request]}")
|
20
20
|
end
|
21
|
+
|
22
|
+
ActiveSupport::Notifications.subscribe('delete_query.chewy') do |name, start, finish, id, payload|
|
23
|
+
duration = ((finish - start).to_f * 10000).round / 10.0
|
24
|
+
Rails.logger.debug(" \e[1m\e[32m#{payload[:index]} Delete by Query (#{duration}ms)\e[0m #{payload[:request]}")
|
25
|
+
end
|
21
26
|
end
|
22
27
|
end
|
23
28
|
end
|
@@ -22,6 +22,11 @@ require 'i18n/core_ext/hash'
|
|
22
22
|
#
|
23
23
|
RSpec::Matchers.define :update_index do |type_name, options = {}|
|
24
24
|
|
25
|
+
if !respond_to?(:failure_message) && respond_to?(:failure_message_for_should)
|
26
|
+
alias :failure_message :failure_message_for_should
|
27
|
+
alias :failure_message_when_negated :failure_message_for_should_not
|
28
|
+
end
|
29
|
+
|
25
30
|
# Specify indexed records by passing record itself or id.
|
26
31
|
#
|
27
32
|
# specify { expect { user.save! }.to update_index(UsersIndex::User).and_reindex(user)
|
@@ -82,19 +87,22 @@ RSpec::Matchers.define :update_index do |type_name, options = {}|
|
|
82
87
|
@only = true
|
83
88
|
end
|
84
89
|
|
90
|
+
def supports_block_expectations?
|
91
|
+
true
|
92
|
+
end
|
93
|
+
|
85
94
|
match do |block|
|
86
95
|
@reindex ||= {}
|
87
96
|
@delete ||= {}
|
88
97
|
@missed_reindex = []
|
89
98
|
@missed_delete = []
|
99
|
+
@updated = []
|
90
100
|
|
91
101
|
type = Chewy.derive_type(type_name)
|
92
|
-
|
93
|
-
type.
|
94
|
-
updated +=
|
95
|
-
updated_document
|
96
|
-
body = updated_document[:index] || updated_document[:delete]
|
97
|
-
updated_document
|
102
|
+
|
103
|
+
allow(type).to receive(:bulk) do |bulk_options|
|
104
|
+
@updated += bulk_options[:body].map do |updated_document|
|
105
|
+
updated_document.deep_symbolize_keys
|
98
106
|
end
|
99
107
|
{}
|
100
108
|
end
|
@@ -105,7 +113,6 @@ RSpec::Matchers.define :update_index do |type_name, options = {}|
|
|
105
113
|
Chewy.atomic { block.call }
|
106
114
|
end
|
107
115
|
|
108
|
-
@updated = updated
|
109
116
|
@updated.each do |updated_document|
|
110
117
|
if body = updated_document[:index]
|
111
118
|
if document = @reindex[body[:_id].to_s]
|
@@ -139,7 +146,7 @@ RSpec::Matchers.define :update_index do |type_name, options = {}|
|
|
139
146
|
@delete.all? { |_, document| document[:match_count] }
|
140
147
|
end
|
141
148
|
|
142
|
-
|
149
|
+
failure_message do
|
143
150
|
output = ''
|
144
151
|
|
145
152
|
if @updated.none?
|
@@ -177,7 +184,7 @@ RSpec::Matchers.define :update_index do |type_name, options = {}|
|
|
177
184
|
output
|
178
185
|
end
|
179
186
|
|
180
|
-
|
187
|
+
failure_message_when_negated do
|
181
188
|
if @updated.any?
|
182
189
|
"Expected index `#{type_name}` not to be updated, but it was with #{
|
183
190
|
@updated.map(&:values).flatten.group_by { |documents| documents[:_id] }.map do |id, documents|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Chewy
|
2
|
+
module Type
|
3
|
+
module Actions
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
# Delete all documents of a type and reimport them
|
8
|
+
# Returns true or false depending on success.
|
9
|
+
#
|
10
|
+
# UsersIndex::User.reset
|
11
|
+
#
|
12
|
+
def reset
|
13
|
+
delete_all
|
14
|
+
import
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -104,7 +104,7 @@ module Chewy
|
|
104
104
|
attr_reader :model, :scope, :options
|
105
105
|
|
106
106
|
def import_ids(ids, import_options = {}, &block)
|
107
|
-
ids
|
107
|
+
ids.uniq!
|
108
108
|
|
109
109
|
indexed = true
|
110
110
|
merged_scope(scoped_model(ids)).find_in_batches(import_options.slice(:batch_size)) do |objects|
|
data/lib/chewy/type/base.rb
CHANGED
@@ -2,6 +2,7 @@ require 'chewy/index/search'
|
|
2
2
|
require 'chewy/type/mapping'
|
3
3
|
require 'chewy/type/wrapper'
|
4
4
|
require 'chewy/type/observe'
|
5
|
+
require 'chewy/type/actions'
|
5
6
|
require 'chewy/type/import'
|
6
7
|
require 'chewy/type/adapter/object'
|
7
8
|
require 'chewy/type/adapter/active_record'
|
@@ -13,6 +14,7 @@ module Chewy
|
|
13
14
|
include Mapping
|
14
15
|
include Wrapper
|
15
16
|
include Observe
|
17
|
+
include Actions
|
16
18
|
include Import
|
17
19
|
|
18
20
|
singleton_class.delegate :client, to: :index
|
data/lib/chewy/type/import.rb
CHANGED
@@ -22,10 +22,12 @@ module Chewy
|
|
22
22
|
bulk_options = import_options.reject { |k, v| ![:refresh, :suffix].include?(k) }.reverse_merge!(refresh: true)
|
23
23
|
|
24
24
|
index.create!(bulk_options.slice(:suffix)) unless index.exists?
|
25
|
+
build_root unless self.root_object
|
25
26
|
|
26
27
|
ActiveSupport::Notifications.instrument 'import_objects.chewy', type: self do |payload|
|
27
28
|
adapter.import(*args, import_options) do |action_objects|
|
28
|
-
|
29
|
+
indexed_objects = self.root_object.parent_id && fetch_indexed_objects(action_objects.values.flatten, bulk_options)
|
30
|
+
body = bulk_body(action_objects, indexed_objects)
|
29
31
|
errors = bulk(bulk_options.merge(body: body)) if body.any?
|
30
32
|
|
31
33
|
fill_payload_import payload, action_objects
|
@@ -72,13 +74,30 @@ module Chewy
|
|
72
74
|
|
73
75
|
private
|
74
76
|
|
75
|
-
def bulk_body
|
76
|
-
action_objects.
|
77
|
-
result.concat(
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
77
|
+
def bulk_body(action_objects, indexed_objects = nil)
|
78
|
+
action_objects.inject([]) do |result, (action, objects)|
|
79
|
+
result.concat(objects.map { |object| bulk_entries(action, object, indexed_objects) }.flatten)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def bulk_entries(action, object, indexed_objects = nil)
|
84
|
+
entry = {}
|
85
|
+
|
86
|
+
entry[:_id] = object.respond_to?(:id) ? object.id : object
|
87
|
+
entry[:data] = object_data(object) unless action == :delete
|
88
|
+
|
89
|
+
if self.root_object.parent_id
|
90
|
+
entry[:parent] = self.root_object.compose_parent(object) if object.respond_to?(:id)
|
91
|
+
end
|
92
|
+
|
93
|
+
indexed_object = indexed_objects && indexed_objects[entry[:_id].to_s]
|
94
|
+
|
95
|
+
if indexed_object && self.root_object.parent_id && action == :delete
|
96
|
+
[{ action => entry.merge(parent: indexed_object[:parent]) }]
|
97
|
+
elsif indexed_object && self.root_object.parent_id && entry[:parent].to_s != indexed_object[:parent]
|
98
|
+
[{ :delete => entry.except(:data).merge(parent: indexed_object[:parent]) }, { action => entry }]
|
99
|
+
else
|
100
|
+
[{ action => entry }]
|
82
101
|
end
|
83
102
|
end
|
84
103
|
|
@@ -118,6 +137,23 @@ module Chewy
|
|
118
137
|
{action => errors}
|
119
138
|
end.reduce(&:merge) || {}
|
120
139
|
end
|
140
|
+
|
141
|
+
def fetch_indexed_objects(objects, options = {})
|
142
|
+
ids = objects.map { |object| object.respond_to?(:id) ? object.id : object }
|
143
|
+
result = client.search index: index.build_index_name(suffix: options[:suffix]), type: type_name, fields: '_parent', body: { query: { ids: { values: ids } } }, search_type: 'scan', scroll: '1m'
|
144
|
+
|
145
|
+
indexed_objects = {}
|
146
|
+
|
147
|
+
while result = client.scroll(scroll_id: result['_scroll_id'], scroll: '1m') do
|
148
|
+
break if result['hits']['hits'].empty?
|
149
|
+
|
150
|
+
result['hits']['hits'].map do |hit|
|
151
|
+
indexed_objects[hit['_id']] = { parent: hit['fields']['_parent'] }
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
indexed_objects
|
156
|
+
end
|
121
157
|
end
|
122
158
|
end
|
123
159
|
end
|
data/lib/chewy/version.rb
CHANGED
data/lib/tasks/chewy.rake
CHANGED
@@ -14,7 +14,7 @@ end
|
|
14
14
|
|
15
15
|
def eager_load_chewy!
|
16
16
|
Rails.application.config.paths['app/chewy'].existent.each do |dir|
|
17
|
-
Dir.glob(File.join(dir, '**/*.rb')).each { |file|
|
17
|
+
Dir.glob(File.join(dir, '**/*.rb')).each { |file| require_dependency file }
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
data/spec/chewy/config_spec.rb
CHANGED
@@ -61,9 +61,9 @@ describe Chewy::Config do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
describe '#atomic?' do
|
64
|
-
its(:atomic?) { should
|
65
|
-
specify { subject.atomic { subject.atomic?.should
|
66
|
-
specify { subject.atomic { }; subject.atomic?.should
|
64
|
+
its(:atomic?) { should eq(false) }
|
65
|
+
specify { subject.atomic { subject.atomic?.should eq(true) } }
|
66
|
+
specify { subject.atomic { }; subject.atomic?.should eq(false) }
|
67
67
|
end
|
68
68
|
|
69
69
|
describe '#atomic' do
|
@@ -6,32 +6,32 @@ describe Chewy::Index::Actions do
|
|
6
6
|
before { stub_index :dummies }
|
7
7
|
|
8
8
|
describe '.exists?' do
|
9
|
-
specify { DummiesIndex.exists?.should
|
9
|
+
specify { DummiesIndex.exists?.should eq(false) }
|
10
10
|
|
11
11
|
context do
|
12
12
|
before { DummiesIndex.create }
|
13
|
-
specify { DummiesIndex.exists?.should
|
13
|
+
specify { DummiesIndex.exists?.should eq(true) }
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
describe '.create' do
|
18
|
-
specify { DummiesIndex.create.should
|
19
|
-
specify { DummiesIndex.create('2013').should
|
18
|
+
specify { DummiesIndex.create["acknowledged"].should eq(true) }
|
19
|
+
specify { DummiesIndex.create('2013')["acknowledged"].should eq(true) }
|
20
20
|
|
21
21
|
context do
|
22
22
|
before { DummiesIndex.create }
|
23
|
-
specify { DummiesIndex.create.should
|
24
|
-
specify { DummiesIndex.create('2013').should
|
23
|
+
specify { DummiesIndex.create.should eq(false) }
|
24
|
+
specify { DummiesIndex.create('2013').should eq(false) }
|
25
25
|
end
|
26
26
|
|
27
27
|
context do
|
28
28
|
before { DummiesIndex.create '2013' }
|
29
|
-
specify { Chewy.client.indices.exists(index: 'dummies').should
|
30
|
-
specify { Chewy.client.indices.exists(index: 'dummies_2013').should
|
29
|
+
specify { Chewy.client.indices.exists(index: 'dummies').should eq(true) }
|
30
|
+
specify { Chewy.client.indices.exists(index: 'dummies_2013').should eq(true) }
|
31
31
|
specify { DummiesIndex.aliases.should == [] }
|
32
32
|
specify { DummiesIndex.indexes.should == ['dummies_2013'] }
|
33
|
-
specify { DummiesIndex.create('2013').should
|
34
|
-
specify { DummiesIndex.create('2014').should
|
33
|
+
specify { DummiesIndex.create('2013').should eq(false) }
|
34
|
+
specify { DummiesIndex.create('2014')["acknowledged"].should eq(true) }
|
35
35
|
|
36
36
|
context do
|
37
37
|
before { DummiesIndex.create '2014' }
|
@@ -41,16 +41,16 @@ describe Chewy::Index::Actions do
|
|
41
41
|
|
42
42
|
context do
|
43
43
|
before { DummiesIndex.create '2013', alias: false }
|
44
|
-
specify { Chewy.client.indices.exists(index: 'dummies').should
|
45
|
-
specify { Chewy.client.indices.exists(index: 'dummies_2013').should
|
44
|
+
specify { Chewy.client.indices.exists(index: 'dummies').should eq(false) }
|
45
|
+
specify { Chewy.client.indices.exists(index: 'dummies_2013').should eq(true) }
|
46
46
|
specify { DummiesIndex.aliases.should == [] }
|
47
47
|
specify { DummiesIndex.indexes.should == [] }
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
describe '.create!' do
|
52
|
-
specify { DummiesIndex.create
|
53
|
-
specify { DummiesIndex.create!('2013').should
|
52
|
+
specify { DummiesIndex.create!["acknowledged"].should eq(true) }
|
53
|
+
specify { DummiesIndex.create!('2013')["acknowledged"].should eq(true) }
|
54
54
|
|
55
55
|
context do
|
56
56
|
before { DummiesIndex.create }
|
@@ -60,12 +60,12 @@ describe Chewy::Index::Actions do
|
|
60
60
|
|
61
61
|
context do
|
62
62
|
before { DummiesIndex.create! '2013' }
|
63
|
-
specify { Chewy.client.indices.exists(index: 'dummies').should
|
64
|
-
specify { Chewy.client.indices.exists(index: 'dummies_2013').should
|
63
|
+
specify { Chewy.client.indices.exists(index: 'dummies').should eq(true) }
|
64
|
+
specify { Chewy.client.indices.exists(index: 'dummies_2013').should eq(true) }
|
65
65
|
specify { DummiesIndex.aliases.should == [] }
|
66
66
|
specify { DummiesIndex.indexes.should == ['dummies_2013'] }
|
67
67
|
specify { expect { DummiesIndex.create!('2013') }.to raise_error }
|
68
|
-
specify { DummiesIndex.create!('2014').should
|
68
|
+
specify { DummiesIndex.create!('2014')["acknowledged"].should eq(true) }
|
69
69
|
|
70
70
|
context do
|
71
71
|
before { DummiesIndex.create! '2014' }
|
@@ -75,53 +75,53 @@ describe Chewy::Index::Actions do
|
|
75
75
|
|
76
76
|
context do
|
77
77
|
before { DummiesIndex.create! '2013', alias: false }
|
78
|
-
specify { Chewy.client.indices.exists(index: 'dummies').should
|
79
|
-
specify { Chewy.client.indices.exists(index: 'dummies_2013').should
|
78
|
+
specify { Chewy.client.indices.exists(index: 'dummies').should eq(false) }
|
79
|
+
specify { Chewy.client.indices.exists(index: 'dummies_2013').should eq(true) }
|
80
80
|
specify { DummiesIndex.aliases.should == [] }
|
81
81
|
specify { DummiesIndex.indexes.should == [] }
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
85
|
describe '.delete' do
|
86
|
-
specify { DummiesIndex.delete.should
|
87
|
-
specify { DummiesIndex.delete('dummies_2013').should
|
86
|
+
specify { DummiesIndex.delete.should eq(false) }
|
87
|
+
specify { DummiesIndex.delete('dummies_2013').should eq(false) }
|
88
88
|
|
89
89
|
context do
|
90
90
|
before { DummiesIndex.create }
|
91
|
-
specify { DummiesIndex.delete.should
|
91
|
+
specify { DummiesIndex.delete["acknowledged"].should eq(true) }
|
92
92
|
|
93
93
|
context do
|
94
94
|
before { DummiesIndex.delete }
|
95
|
-
specify { Chewy.client.indices.exists(index: 'dummies').should
|
95
|
+
specify { Chewy.client.indices.exists(index: 'dummies').should eq(false) }
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
99
|
context do
|
100
100
|
before { DummiesIndex.create '2013' }
|
101
|
-
specify { DummiesIndex.delete('2013').should
|
101
|
+
specify { DummiesIndex.delete('2013')["acknowledged"].should eq(true) }
|
102
102
|
|
103
103
|
context do
|
104
104
|
before { DummiesIndex.delete('2013') }
|
105
|
-
specify { Chewy.client.indices.exists(index: 'dummies').should
|
106
|
-
specify { Chewy.client.indices.exists(index: 'dummies_2013').should
|
105
|
+
specify { Chewy.client.indices.exists(index: 'dummies').should eq(false) }
|
106
|
+
specify { Chewy.client.indices.exists(index: 'dummies_2013').should eq(false) }
|
107
107
|
end
|
108
108
|
|
109
109
|
context do
|
110
110
|
before { DummiesIndex.create '2014' }
|
111
|
-
specify { DummiesIndex.delete.should
|
111
|
+
specify { DummiesIndex.delete["acknowledged"].should eq(true) }
|
112
112
|
|
113
113
|
context do
|
114
114
|
before { DummiesIndex.delete }
|
115
|
-
specify { Chewy.client.indices.exists(index: 'dummies').should
|
116
|
-
specify { Chewy.client.indices.exists(index: 'dummies_2013').should
|
117
|
-
specify { Chewy.client.indices.exists(index: 'dummies_2014').should
|
115
|
+
specify { Chewy.client.indices.exists(index: 'dummies').should eq(false) }
|
116
|
+
specify { Chewy.client.indices.exists(index: 'dummies_2013').should eq(false) }
|
117
|
+
specify { Chewy.client.indices.exists(index: 'dummies_2014').should eq(false) }
|
118
118
|
end
|
119
119
|
|
120
120
|
context do
|
121
121
|
before { DummiesIndex.delete('2014') }
|
122
|
-
specify { Chewy.client.indices.exists(index: 'dummies').should
|
123
|
-
specify { Chewy.client.indices.exists(index: 'dummies_2013').should
|
124
|
-
specify { Chewy.client.indices.exists(index: 'dummies_2014').should
|
122
|
+
specify { Chewy.client.indices.exists(index: 'dummies').should eq(true) }
|
123
|
+
specify { Chewy.client.indices.exists(index: 'dummies_2013').should eq(true) }
|
124
|
+
specify { Chewy.client.indices.exists(index: 'dummies_2014').should eq(false) }
|
125
125
|
end
|
126
126
|
end
|
127
127
|
end
|
@@ -133,48 +133,48 @@ describe Chewy::Index::Actions do
|
|
133
133
|
|
134
134
|
context do
|
135
135
|
before { DummiesIndex.create }
|
136
|
-
specify { DummiesIndex.delete
|
136
|
+
specify { DummiesIndex.delete!["acknowledged"].should eq(true) }
|
137
137
|
|
138
138
|
context do
|
139
139
|
before { DummiesIndex.delete! }
|
140
|
-
specify { Chewy.client.indices.exists(index: 'dummies').should
|
140
|
+
specify { Chewy.client.indices.exists(index: 'dummies').should eq(false) }
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
144
|
context do
|
145
145
|
before { DummiesIndex.create '2013' }
|
146
|
-
specify { DummiesIndex.delete!('2013').should
|
146
|
+
specify { DummiesIndex.delete!('2013')["acknowledged"].should eq(true) }
|
147
147
|
|
148
148
|
context do
|
149
149
|
before { DummiesIndex.delete!('2013') }
|
150
|
-
specify { Chewy.client.indices.exists(index: 'dummies').should
|
151
|
-
specify { Chewy.client.indices.exists(index: 'dummies_2013').should
|
150
|
+
specify { Chewy.client.indices.exists(index: 'dummies').should eq(false) }
|
151
|
+
specify { Chewy.client.indices.exists(index: 'dummies_2013').should eq(false) }
|
152
152
|
end
|
153
153
|
|
154
154
|
context do
|
155
155
|
before { DummiesIndex.create '2014' }
|
156
|
-
specify { DummiesIndex.delete
|
156
|
+
specify { DummiesIndex.delete!["acknowledged"].should eq(true) }
|
157
157
|
|
158
158
|
context do
|
159
159
|
before { DummiesIndex.delete! }
|
160
|
-
specify { Chewy.client.indices.exists(index: 'dummies').should
|
161
|
-
specify { Chewy.client.indices.exists(index: 'dummies_2013').should
|
162
|
-
specify { Chewy.client.indices.exists(index: 'dummies_2014').should
|
160
|
+
specify { Chewy.client.indices.exists(index: 'dummies').should eq(false) }
|
161
|
+
specify { Chewy.client.indices.exists(index: 'dummies_2013').should eq(false) }
|
162
|
+
specify { Chewy.client.indices.exists(index: 'dummies_2014').should eq(false) }
|
163
163
|
end
|
164
164
|
|
165
165
|
context do
|
166
166
|
before { DummiesIndex.delete!('2014') }
|
167
|
-
specify { Chewy.client.indices.exists(index: 'dummies').should
|
168
|
-
specify { Chewy.client.indices.exists(index: 'dummies_2013').should
|
169
|
-
specify { Chewy.client.indices.exists(index: 'dummies_2014').should
|
167
|
+
specify { Chewy.client.indices.exists(index: 'dummies').should eq(true) }
|
168
|
+
specify { Chewy.client.indices.exists(index: 'dummies_2013').should eq(true) }
|
169
|
+
specify { Chewy.client.indices.exists(index: 'dummies_2014').should eq(false) }
|
170
170
|
end
|
171
171
|
end
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
175
175
|
describe '.purge' do
|
176
|
-
specify { DummiesIndex.purge.should
|
177
|
-
specify { DummiesIndex.purge('2013').should
|
176
|
+
specify { DummiesIndex.purge["acknowledged"].should eq(true) }
|
177
|
+
specify { DummiesIndex.purge('2013')["acknowledged"].should eq(true) }
|
178
178
|
|
179
179
|
context do
|
180
180
|
before { DummiesIndex.purge }
|
@@ -220,8 +220,8 @@ describe Chewy::Index::Actions do
|
|
220
220
|
end
|
221
221
|
|
222
222
|
describe '.purge!' do
|
223
|
-
specify { DummiesIndex.purge
|
224
|
-
specify { DummiesIndex.purge!('2013').should
|
223
|
+
specify { DummiesIndex.purge!["acknowledged"].should eq(true) }
|
224
|
+
specify { DummiesIndex.purge!('2013')["acknowledged"].should eq(true) }
|
225
225
|
|
226
226
|
context do
|
227
227
|
before { DummiesIndex.purge! }
|
@@ -324,8 +324,8 @@ describe Chewy::Index::Actions do
|
|
324
324
|
|
325
325
|
before { City.create!(name: 'Moscow') }
|
326
326
|
|
327
|
-
specify { CitiesIndex.reset!.should
|
328
|
-
specify { CitiesIndex.reset!('2013').should
|
327
|
+
specify { CitiesIndex.reset!.should eq(true) }
|
328
|
+
specify { CitiesIndex.reset!('2013').should eq(true) }
|
329
329
|
|
330
330
|
context do
|
331
331
|
before { CitiesIndex.reset! }
|
@@ -364,7 +364,7 @@ describe Chewy::Index::Actions do
|
|
364
364
|
specify { CitiesIndex.all.should have(1).item }
|
365
365
|
specify { CitiesIndex.aliases.should == [] }
|
366
366
|
specify { CitiesIndex.indexes.should == ['cities_2014'] }
|
367
|
-
specify { Chewy.client.indices.exists(index: 'cities_2013').should
|
367
|
+
specify { Chewy.client.indices.exists(index: 'cities_2013').should eq(false) }
|
368
368
|
end
|
369
369
|
|
370
370
|
context do
|
@@ -373,7 +373,7 @@ describe Chewy::Index::Actions do
|
|
373
373
|
specify { CitiesIndex.all.should have(1).item }
|
374
374
|
specify { CitiesIndex.aliases.should == [] }
|
375
375
|
specify { CitiesIndex.indexes.should == [] }
|
376
|
-
specify { Chewy.client.indices.exists(index: 'cities_2013').should
|
376
|
+
specify { Chewy.client.indices.exists(index: 'cities_2013').should eq(false) }
|
377
377
|
end
|
378
378
|
end
|
379
379
|
end
|