Skip to content

Commit

Permalink
feat: forwards the import and reindex options during index reset
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosgz committed Aug 8, 2024
1 parent 6b4a582 commit 0a9bf46
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/esse/index/indices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def reset_index(suffix: index_suffix, settings: nil, optimize: true, import: tru
cluster.api.delete_index(index: index_name)
end
if import
import(**options, suffix: suffix, refresh: refresh)
import_kwargs = import.is_a?(Hash) ? import : {}
import_kwargs[:refresh] ||= refresh if refresh
import(**options, **import_kwargs, suffix: suffix)
elsif reindex && (source_indexes = indices_pointing_to_alias).any?
reindex_kwargs = reindex.is_a?(Hash) ? reindex : {}
reindex_kwargs[:wait_for_completion] = true unless reindex_kwargs.key?(:wait_for_completion)
Expand Down
30 changes: 30 additions & 0 deletions spec/support/shared_examples/index_reset_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@
end
end

it 'forwads the import options to the import method' do
es_client do |client, _conf, cluster|
GeosIndex.create_index(alias: true, suffix: '2021')
expect {
GeosIndex.reset_index(suffix: index_suffix, import: { refresh: true })
}.not_to raise_error

expect(GeosIndex.indices_pointing_to_alias).to eq(["#{GeosIndex.index_name}_#{index_suffix}"])
expect(GeosIndex.index_exist?(suffix: '2021')).to eq(true)
expect(GeosIndex.index_exist?(suffix: index_suffix)).to eq(true)
expect(GeosIndex.count).to be_positive
end
end

it 'reindex data from the old index to the new index' do
es_client do |client, _conf, cluster|
GeosIndex.create_index(alias: true, suffix: '2021')
Expand All @@ -83,5 +97,21 @@
expect(GeosIndex.count).to be_positive
end
end

it 'forwads the reindex options to the reindex method' do
es_client do |client, _conf, cluster|
GeosIndex.create_index(alias: true, suffix: '2021')
GeosIndex.import(refresh: true)

expect {
GeosIndex.reset_index(suffix: index_suffix, import: false, reindex: { wait_for_completion: true }, refresh: true)
}.not_to raise_error

expect(GeosIndex.indices_pointing_to_alias).to eq(["#{GeosIndex.index_name}_#{index_suffix}"])
expect(GeosIndex.index_exist?(suffix: '2021')).to eq(true)
expect(GeosIndex.index_exist?(suffix: index_suffix)).to eq(true)
expect(GeosIndex.count).to be_positive
end
end
end
end

0 comments on commit 0a9bf46

Please sign in to comment.