Skip to content

Commit

Permalink
indicate active index in stats rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jul 27, 2019
1 parent 4420fdf commit 18e34e8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -398,17 +398,18 @@ 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"
active_index = self.active_index
inactive_index = self.inactive_index

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")
stats = client.indices.stats index: [active_index, inactive_index], docs: true
active_index_count = stats.dig("indices", active_index, "primaries", "docs", "count")
inactive_index_count = stats.dig("indices", inactive_index, "primaries", "docs", "count")
database_count = self.all.count

message = "Index #{index_name} has #{index_name_count} documents, " \
"#{alternate_index_name} has #{alternate_index_name_count} documents, database has #{database_count} documents."
message = "Active index #{active_index} has #{active_index_count} documents, " \
"inactive index #{inactive_index} has #{inactive_index_count} documents, " \
"database has #{database_count} documents."
return message
end

Expand Down

0 comments on commit 18e34e8

Please sign in to comment.