0

For now I have:

desc "Index Elastic Search"
namespace :tire do
  namespace :import do
    task all: :environment do
      aliases = Tire::Configuration.client.get(Tire::Configuration.url + '/_aliases').body
      indexes_names = MultiJson.load(aliases).keys

      indexes_names.each do |name|
        index = Tire::Index.new name
        index.delete
        index.import
        index.refresh
        puts "[INFO] #{name} re-indexed"
      end
    end
  end
end

But I get an error

wrong number of arguments (0 for 1)
/Users/rege/.rvm/gems/ruby-1.9.3-p194@network/gems/tire-0.5.2/lib/tire/index.rb:185:in `import'
/Users/rege/Code/Network/lib/tasks/tire.rake:15:in `block (4 levels) in <top (required)>'
/Users/rege/Code/Network/lib/tasks/tire.rake:12:in `each'
/Users/rege/Code/Network/lib/tasks/tire.rake:12:in `block (3 levels) in <top (required)>'
Tasks: TOP => tire:import:all
tomekfranek
  • 6,852
  • 8
  • 45
  • 80

1 Answers1

1

You need to tell each index what to import. Assuming you use the default index naming convention, then you need to do this:

index.import name.singularize.camelcase.constantize.all

UPDATE: Given your naming style, you can use this:

index.import name.gsub(/^myapp_(development|production)__/, '').singularize.camelcase.constantize.all
Ahmad Sherif
  • 5,923
  • 3
  • 21
  • 27
  • I have before each index name name of my app and environtment: ``myapp_development__links`` So your solution gives me: ``uninitialized constant MyAppDevelopmentLink`` – tomekfranek Jan 09 '13 at 00:52
  • I also had add ``test`` hmm, but I wonder is that proper way to do that? – tomekfranek Jan 09 '13 at 01:23
  • One other approach is to iterate over your models searching for ones that have Tire included, but whatever works for you :). – Ahmad Sherif Jan 09 '13 at 01:26