我已经索引了一个Car
模型与一个汽车记录mercedes benz
在数据库中。如果我搜索的单词benz
我得到一个错误:钢轨轮胎elasticsearch奇怪的错误
ActiveRecord::RecordNotFound in CarsController#index
Couldn't find all Cars with IDs (1, 3) (found 1 results, but was looking for 2)
如果我搜索hello
我得到:
Couldn't find Car with id=2
其他随机搜索字词工作返回准确的结果。
所以它基本上是由随机搜索术语产生的随机错误。这可能是什么原因?
控制器:
def index
if params[:query].present?
@cars = Car.search(params)
else
@cars = Car.paginate(:page => params[:page], :per_page => 10)
end
end
型号:
def self.search(params)
tire.search(load: true, page: params[:page], per_page: 10) do |s|
s.query { string params[:query]} if params[:query].present?
end
end
我觉得你的指数是不是在你的数据库同步。您已从您的数据库中删除了一些汽车记录,但它们并未从搜索索引中删除。重新创建索引并尝试搜索。 – 2013-02-22 15:00:04
我找不到轮胎reindex命令。我可以运行rake db:drop + rake db:setup to reindex? – 2013-02-22 15:10:23
您可以删除索引(例如:curl -XDELETE'http:// localhost:9200/cars /'),然后重新索引(rake setup:tire)。 – 2013-02-22 15:15:08