From 2fe87e9dc605905c8131dcd69929ff77b8858f6e Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Thu, 31 Mar 2022 21:58:34 -0400 Subject: [PATCH 1/2] Issue #794 - ES - DOIs Deposited in the Wrong Index --- app/models/concerns/indexable.rb | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index 1dcfd168f..1d72e69f8 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -1201,20 +1201,36 @@ 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 + 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 From f3cf57a64b85e4a0b6adda8edba8b743143dc566 Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Wed, 6 Apr 2022 10:00:32 -0400 Subject: [PATCH 2/2] Issue #794 - ES - DOIs Deposited in the Wrong Index --- app/models/concerns/indexable.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index 1d72e69f8..be6dee8ce 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -1219,6 +1219,8 @@ def active_index break end end + # If it gets here, just return the first. + ret = h.keys.first end end