Ruby on rails - Elasticsearch & Bonsai: IndexMissingException on Heroku,在本地工作正常



构建我的第一个rails应用程序,并且在Heroku上运行Elasticsearch遇到问题。

本地工作完美。

在Heroku上我可以打开搜索页面,但是当我试图执行搜索时,我得到下面的错误:

Heroku日志显示:

2015-05-18T12:05:15.969673+00:00 app[web.1]: ActionView::Template::Error ([404] {"error":"IndexMissingException[[homes] missing]","status":404}):
2015-05-18T12:05:15.969674+00:00 app[web.1]:      9: <% end %>
2015-05-18T12:05:15.969676+00:00 app[web.1]:     10:  
2015-05-18T12:05:15.969677+00:00 app[web.1]:     11: <ul>
2015-05-18T12:05:15.969678+00:00 app[web.1]:     12:   <% @homes.each do |home| %>
2015-05-18T12:05:15.969679+00:00 app[web.1]:     13:     <li>
2015-05-18T12:05:15.969680+00:00 app[web.1]:     14:       <h3>
2015-05-18T12:05:15.969682+00:00 app[web.1]:     15:         <%= link_to home.name, controller: "homes", action: "show", id: home._id%>
2015-05-18T12:05:15.969683+00:00 app[web.1]:   app/views/search/search.html.erb:12:in `_app_views_search_search_html_erb___1261310385184340853_69929402195100'

宝石:

gem 'elasticsearch-model'
gem 'elasticsearch-rails'
gem 'bonsai-elasticsearch-rails', '~> 0.0.4'

搜索控制器:

class SearchController < ApplicationController
    def search
      if params[:q].nil?
        @homes = []
      else
        @homes = Home.search params[:q]
      end
    end 
end

搜索视图:

<h1>Homes Search</h1>
<%= form_for search_path, method: :get do |f| %>
  <p>
    <%= f.label "Search for" %>
    <%= text_field_tag :q, params[:q] %>
    <%= submit_tag "Go", name: nil %>
  </p>
<% end %>
<ul>
  <% @homes.each do |home| %>
    <li>
      <h3>
        <%= link_to home.name, controller: "homes", action: "show", id: home._id%>
      </h3>
    </li>
  <% end %>
</ul>

任何建议都将非常感谢!

问题与此问题类似。

解决方案包括

  1. 运行这里突出显示的任务
  2. 确保elasticsearch.rake存在
  3. 最后,如果404仍然发生,使用curl -XPOST http://account.region.bonsai.io/homes
  4. 手动创建索引

最新更新