From 193bcca1785743b47b5670ea57856fc6fa3357fd Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Mon, 15 Jul 2019 00:01:40 +0200 Subject: [PATCH] fix index_stats method. #302 --- app/models/concerns/indexable.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index 914aeaeee..6c6f7adb0 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -396,13 +396,17 @@ def upgrade_index # show stats for both indexes def index_stats(options={}) + index_name = self.index_name + "_v1" + alternate_index_name = self.index_name + "_v2" + + client = Elasticsearch::Model.client stats = client.indices.stats index: [index_name, alternate_index_name], docs: true index_name_count = stats.dig("indices", index_name, "primaries", "docs", "count") alternate_index_name_count = stats.dig("indices", alternate_index_name, "primaries", "docs", "count") + last_id = self.maximum(:id) || 1 - puts stats - message = "Index #{index_name} has #{index_name_count} documents." \ - "Index #{alternate_index_name} has #{alternate_index_name_count} documents." + message = "Index #{index_name} has #{index_name_count} documents, " \ + "#{alternate_index_name} has #{alternate_index_name_count} documents, last_id is #{last_id}." return message end