Fixes #3955 - Elasticsearch-Rebuild does not index from new to old.
This commit is contained in:
parent
a7861725a1
commit
ad2b3e1dca
1 changed files with 13 additions and 10 deletions
|
@ -216,23 +216,26 @@ reload search index with full data
|
||||||
def search_index_reload
|
def search_index_reload
|
||||||
tolerance = 10
|
tolerance = 10
|
||||||
tolerance_count = 0
|
tolerance_count = 0
|
||||||
batch_size = 100
|
query = order(created_at: :desc)
|
||||||
query = all.order(created_at: :desc)
|
|
||||||
total = query.count
|
total = query.count
|
||||||
query.find_in_batches(batch_size: batch_size).with_index do |group, batch|
|
record_count = 0
|
||||||
group.each do |item|
|
batch_size = 100
|
||||||
next if item.ignore_search_indexing?(:destroy)
|
query.as_batches(size: batch_size) do |record|
|
||||||
|
if !record.ignore_search_indexing?(:destroy)
|
||||||
begin
|
begin
|
||||||
item.search_index_update_backend
|
record.search_index_update_backend
|
||||||
rescue => e
|
rescue => e
|
||||||
logger.error "Unable to send #{item.class}.find(#{item.id}).search_index_update_backend backend: #{e.inspect}"
|
logger.error "Unable to send #{record.class}.find(#{record.id}).search_index_update_backend backend: #{e.inspect}"
|
||||||
tolerance_count += 1
|
tolerance_count += 1
|
||||||
sleep 15
|
sleep 15
|
||||||
raise "Unable to send #{item.class}.find(#{item.id}).search_index_update_backend backend: #{e.inspect}" if tolerance_count == tolerance
|
raise "Unable to send #{record.class}.find(#{record.id}).search_index_update_backend backend: #{e.inspect}" if tolerance_count == tolerance
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
puts "\t#{[(batch + 1) * batch_size, total].min}/#{total}" # rubocop:disable Rails/Output
|
|
||||||
|
record_count += 1
|
||||||
|
if (record_count % batch_size).zero? || record_count == total
|
||||||
|
puts "\t#{record_count}/#{total}" # rubocop:disable Rails/Output
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue