Commit 07d4f43b by Jay Zoldak

Merge pull request #35 from edx/feature/kevin/batchify_index_solo_commit

update elastic search to reindex nondestructively, in batch, and then swap out new index for old after new index is done
parents a23e6f5f d01922ed
...@@ -224,9 +224,40 @@ namespace :db do ...@@ -224,9 +224,40 @@ namespace :db do
end end
task :reindex_search => :environment do task :reindex_search => :environment do
Tire.index('comment_threads').delete Mongoid.identity_map_enabled = false
CommentThread.create_elasticsearch_index
Tire.index('comment_threads') { import CommentThread.all } klass = CommentThread
ENV['CLASS'] = klass.name
ENV['INDEX'] = new_index = klass.tire.index.name << '_' << Time.now.strftime('%Y%m%d%H%M%S')
Rake::Task["tire:import"].invoke
puts '[IMPORT] about to swap index'
if a = Tire::Alias.find(klass.tire.index.name)
puts "[IMPORT] aliases found: #{Tire::Alias.find(klass.tire.index.name).indices.to_ary.join(',')}. deleting."
old_indices = Tire::Alias.find(klass.tire.index.name).indices
old_indices.each do |index|
a.indices.delete index
end
a.indices.add new_index
a.save
old_indices.each do |index|
puts "[IMPORT] deleting index: #{index}"
i = Tire::Index.new(index)
i.delete if i.exists?
end
else
puts "[IMPORT] no aliases found. deleting index. creating new one and setting up alias."
klass.tire.index.delete
a = Tire::Alias.new
a.name(klass.tire.index.name)
a.index(new_index)
a.save
end
puts "[IMPORT] done. Index: '#{new_index}' created."
end end
task :add_anonymous_to_peers => :environment do task :add_anonymous_to_peers => :environment do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment