lib/searchkick/index.rb in searchkick-2.0.1 vs lib/searchkick/index.rb in searchkick-2.0.2
- old
+ new
@@ -36,20 +36,21 @@
def settings
client.indices.get_settings index: name
end
- def swap(new_name)
+ def promote(new_name)
old_indices =
begin
client.indices.get_alias(name: name).keys
rescue Elasticsearch::Transport::Transport::Errors::NotFound
{}
end
actions = old_indices.map { |old_name| {remove: {index: old_name, alias: name}} } + [{add: {index: new_name, alias: name}}]
client.indices.update_aliases body: {actions: actions}
end
+ alias_method :swap, :promote
# record based
def store(record)
bulk_index([record])
@@ -184,33 +185,33 @@
response["hits"]["total"]
end
# https://gist.github.com/jarosan/3124884
# http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/
- def reindex_scope(scope, import: true, resume: false)
+ def reindex_scope(scope, import: true, resume: false, retain: false)
if resume
index_name = all_indices.sort.last
raise Searchkick::Error, "No index to resume" unless index_name
index = Searchkick::Index.new(index_name)
else
- clean_indices
+ clean_indices unless retain
index = create_index(index_options: scope.searchkick_index_options)
end
# check if alias exists
if alias_exists?
- # import before swap
+ # import before promotion
index.import_scope(scope, resume: resume) if import
# get existing indices to remove
- swap(index.name)
- clean_indices
+ promote(index.name)
+ clean_indices unless retain
else
delete if exists?
- swap(index.name)
+ promote(index.name)
- # import after swap
+ # import after promotion
index.import_scope(scope, resume: resume) if import
end
index.refresh