Skip to content

Commit

Permalink
fix: do not delete exiting index when the given suffix already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosgz committed Jun 28, 2024
1 parent 6830327 commit b9a93b7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/esse/index/indices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ def create_index(suffix: nil, body: nil, **options)
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html
def reset_index(suffix: index_suffix, optimize: true, import: true, reindex: false, **options)
cluster.throw_error_when_readonly!
existing = []
suffix ||= Esse.timestamp
suffix = Esse.timestamp while index_exist?(suffix: suffix).tap { |exist| existing << suffix if exist }

if suffix && index_exist?(suffix: suffix)
existing = [suffix]
suffix = Esse.timestamp while index_exist?(suffix: suffix).tap { |exist| existing << suffix if exist }
Esse.logger.warn { "Index with suffix #{existing.join(', ')} already exists. Using #{suffix} instead. Consider using a different suffix" }
else
suffix = Esse.timestamp while index_exist?(suffix: suffix)
end

if optimize
definition = [settings_hash, mappings_hash].reduce(&:merge)
Expand All @@ -77,7 +82,6 @@ def reset_index(suffix: index_suffix, optimize: true, import: true, reindex: fal
update_settings(suffix: suffix)
end
update_aliases(suffix: suffix)
existing.each { |s| delete_index!(**options, suffix: s) }
true
end

Expand Down

0 comments on commit b9a93b7

Please sign in to comment.