我已經索引了一個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