Skip to content

Commit

Permalink
Issue #794 - ES - DOIs Deposited in the Wrong Index
Browse files Browse the repository at this point in the history
  • Loading branch information
svogt0511 committed Apr 7, 2022
1 parent 0b35076 commit cdae37f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1203,24 +1203,29 @@ def switch_index(options = {})
# 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
ret = nil

alias_name = index_name
client = Elasticsearch::Model.client

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

if h && !h.key?(:error)
if h && (!h.key?(:error) && !h.key?("error"))

if h.size == 1
ret = h.keys.first
else
# Looping through indices that have alias_name.
h.each do |key, value|
if value.dig(:aliases, :dois, :is_write_index)
if value.dig("aliases", alias_name, "is_write_index") == true
ret = key
break
end
end
# If it gets here, just return the first.
ret = h.keys.first
# If it gets here with no value, just return the first key.
if ret.nil?
ret = h.keys.first
end
end
end

Expand Down

0 comments on commit cdae37f

Please sign in to comment.