Skip to content

Commit

Permalink
Merge pull request #800 from datacite/br-issue-794
Browse files Browse the repository at this point in the history
Issue #794 - ES - DOIs Deposited in the Wrong Index (cleanup)
  • Loading branch information
svogt0511 authored Apr 8, 2022
2 parents 739d6aa + 27064c9 commit 2c8a579
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1208,9 +1208,8 @@ def active_index
alias_name = index_name
client = Elasticsearch::Model.client

h = client.indices.get_alias(name: alias_name)

if h && (!h.key?(:error) && !h.key?("error"))
begin
h = client.indices.get_alias(name: alias_name)

if h.size == 1
ret = h.keys.first
Expand All @@ -1227,18 +1226,27 @@ def active_index
ret = h.keys.first
end
end
rescue Elasticsearch::Transport::Transport::Errors::NotFound => e
Rails.logger.error e.message
end

ret
end

# Return the inactive index, i.e. the index that is not aliased
def inactive_index
ret = nil

active_index = self.active_index
index_name = self.index_name + "_v1"
alternate_index_name = self.index_name + "_v2"

active_index.end_with?("v1") ? alternate_index_name : index_name
if !active_index.nil?
index_name = self.index_name + "_v1"
alternate_index_name = self.index_name + "_v2"

ret = active_index.end_with?("v1") ? alternate_index_name : index_name
end

ret
end

# create index template
Expand Down

0 comments on commit 2c8a579

Please sign in to comment.