Elasticsearch和Tyre Gem:“IndexMissingException [[products] missing]”?

时间:2012-08-15 11:15:06

标签: ruby-on-rails ruby-on-rails-3 elasticsearch tire

我不确定如何将我的产品编入索引,因为我认为这就是我收到此错误的原因:

Tire::Search::SearchRequestFailed in SearchController#results

404 : {"error":"IndexMissingException[[products] missing]","status":404}

这是我的产品型号:

class Product < ActiveRecord::Base
  attr_accessible :name, :description
  belongs_to :user

  include Tire::Model::Search
  include Tire::Model::Callbacks

  def self.search(params)
     tire.search(load: true, page: params[:page], per_page: 10) do
        query { string params[:query]} if params[:query].present?
     end
  end
end

如果出现问题,如何为我的产品编制索引?

谢谢。

1 个答案:

答案 0 :(得分:12)

运行以下rake任务

rake environment tire:import CLASS='Product'