Skip to content

Commit feae24c

Browse files
committed
[MODEL] Fix import method to pass index name on refresh
Fixes #506
1 parent 109c155 commit feae24c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

elasticsearch-model/lib/elasticsearch/model/importing.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def import(options={}, &block)
130130
errors += response['items'].select { |k, v| k.values.first['error'] }
131131
end
132132

133-
self.refresh_index! if refresh
133+
self.refresh_index! index: target_index if refresh
134134

135135
case return_value
136136
when 'errors'

elasticsearch-model/test/unit/importing_test.rb

+21
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,27 @@ def importing_mixin
146146
end
147147
end
148148

149+
context "with the refresh option" do
150+
should "refresh the index" do
151+
DummyImportingModel.expects(:__find_in_batches).with do |options|
152+
assert_equal 'bar', options[:foo]
153+
assert_nil options[:refresh]
154+
true
155+
end
156+
157+
DummyImportingModel.expects(:refresh_index!).with do |options|
158+
assert_equal 'foo', options[:index]
159+
true
160+
end
161+
162+
DummyImportingModel.expects(:index_name).returns('foo')
163+
DummyImportingModel.expects(:document_type).returns('foo')
164+
DummyImportingModel.stubs(:index_exists?).returns(true)
165+
166+
DummyImportingModel.import refresh: true, foo: 'bar'
167+
end
168+
end
169+
149170
should "allow passing a different index / type" do
150171
Elasticsearch::Model::Adapter.expects(:from_class)
151172
.with(DummyImportingModel)

0 commit comments

Comments
 (0)