0

现在我有:

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

但我得到一个错误

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
4

1 回答 1

1

您需要告诉每个索引要导入什么。假设您使用默认索引命名约定,那么您需要这样做:

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

更新:鉴于您的命名风格,您可以使用:

index.import name.gsub(/^myapp_(development|production)__/, '').singularize.camelcase.constantize.all
于 2013-01-08T23:55:03.323 回答