Skip to content

Instantly share code, notes, and snippets.

@jarosan
jarosan / elasticsearch.rake
Created July 16, 2012 20:37
Elasticsearch reindex task
# Run with: rake environment elasticsearch:reindex
namespace :elasticsearch do
desc "re-index elasticsearch"
task :reindex => :environment do
klass = Place
ENV['CLASS'] = klass.name
ENV['INDEX'] = new_index = klass.tire.index.name << '_' << Time.now.strftime('%Y%m%d%H%M%S')
@nz
nz / 01 sample reindexing.rb
Created August 16, 2011 17:37
Custom reindexing with Sunspot
# Custom reindexing with Sunspot
# Use your own finder, rescue and log exceptions, etc.
# Throw this in a rake task, or class method to run from the console
Article.find_in_batches(:batch_size => 100) do |articles|
articles.each do |article|
tries = 0
begin
article.solr_index
rescue RSolr::RequestError => e