Skip to content

Commit

Permalink
fix index_stats method. #302
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jul 14, 2019
1 parent 674dc80 commit 193bcca
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 193bcca

Please sign in to comment.