Skip to content

Commit

Permalink
Split the alias update call in two calls
Browse files Browse the repository at this point in the history
  • Loading branch information
alranel committed Feb 5, 2019
1 parent e601fea commit f743b63
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions lib/searchyll/indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,38 @@ def finalize_replication(http)
# hot swap the index into the canonical alias
def finalize_aliases(http)
update_aliases = http_post('/_aliases')

# perform removal and addition in two different calls so that
# the second one is performed even if the first one fails
if !old_indices.empty?
update_aliases.body = {
actions: [
{ remove: {
index: old_indices.join(','),
alias: configuration.elasticsearch_index_base_name
} }
]
}.to_json
res = http.request(update_aliases)
if !res.kind_of?(Net::HTTPSuccess)
$stderr.puts "Elasticsearch returned an error when removing old aliases: " + res.message + " " + res.body
exit
end
end

update_aliases.body = {
actions: [
{ remove: {
index: old_indices.join(','),
alias: configuration.elasticsearch_index_base_name
} },
{ add: {
index: elasticsearch_index_name,
alias: configuration.elasticsearch_index_base_name
} }
]
}.to_json
http.request(update_aliases)
res = http.request(update_aliases)
if !res.kind_of?(Net::HTTPSuccess)
$stderr.puts "Elasticsearch returned an error when assigning the new alias: " + res.message + " " + res.body
exit
end
end

# delete old indices after a successful reindexing run
Expand Down

0 comments on commit f743b63

Please sign in to comment.