Skip to content

Commit

Permalink
Merge pull request #796 from datacite/issue-794
Browse files Browse the repository at this point in the history
Issue #794 - ES - DOIs Deposited in the Wrong Index
  • Loading branch information
svogt0511 authored Apr 6, 2022
2 parents 16388b0 + f3cf57a commit 0b35076
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1201,20 +1201,38 @@ def switch_index(options = {})
end

# Return the active index, i.e. the index that is aliased
# Don't rely on the first index being the correct one.
def active_index
alias_name = index_name
client = Elasticsearch::Model.client
client.indices.get_alias(name: alias_name).keys.first

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

if h && !h.key?(:error)
if h.size == 1
ret = h.keys.first
else
h.each do |key, value|
if value.dig(:aliases, :dois, :is_write_index)
ret = key
break
end
end
# If it gets here, just return the first.
ret = h.keys.first
end
end

ret
end

# Return the inactive index, i.e. the index that is not aliased
def inactive_index
alias_name = index_name
active_index = self.active_index
index_name = self.index_name + "_v1"
alternate_index_name = self.index_name + "_v2"

client = Elasticsearch::Model.client
active_index = client.indices.get_alias(name: alias_name).keys.first
active_index.end_with?("v1") ? alternate_index_name : index_name
end

Expand Down

0 comments on commit 0b35076

Please sign in to comment.