2

Building my first rails app and having issues getting Elasticsearch to run on Heroku.

Local works perfect.

On Heroku I can open the search page, but when I try to perform a search I get the error below:

Heroku logs show:

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'

Gems:

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

Search Controller:

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

Search View:

<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>

Any suggestions would be greatly appreciated!

janfoeh
  • 10,243
  • 2
  • 31
  • 56
LarryC
  • 35
  • 4
  • Can you also show your logs from the ES server? – Val May 18 '15 at 12:21
  • @janfoeh - Not sure how to access the ES server logs, can you point me in the right direction? – LarryC May 18 '15 at 12:34
  • @Val that question is probably better directed at you, as I am not familiar with Elasticsearch :) But if I had to guess, I would start by logging into your Bonsai dashboard. – janfoeh May 18 '15 at 12:37
  • Are you sure you've properly set up your `homes` index and mapping type on your Heroku ES instance? What do you see when running `curl -XGET http://account.region.bonsai.io/homes/_search`, where `account` and `region` should be replaced with your own settings. – Val May 18 '15 at 12:49
  • @Val - when I run that I get: {"error":"IndexMissingException[[homes] missing]","status":404} – LarryC May 18 '15 at 13:00
  • Then you just need to set up your `homes` index the same way you did on your local workstation since you said it was working fine locally. Does it make sense? – Val May 18 '15 at 13:02
  • Hmmm, when I set it up locally it just worked, I didn't have to run through setting up the the index. I was following [this tutorial](http://www.sitepoint.com/full-text-search-rails-elasticsearch/) – LarryC May 18 '15 at 13:09
  • I see. Have you been through the "Custom Mapping" part, too? – Val May 18 '15 at 13:13
  • No, I haven't gone past the 'Enhance the search' part. Was trying to make sure the basics worked going further. – LarryC May 18 '15 at 13:16
  • Looks a lot like [this issue](https://github.com/elastic/elasticsearch-rails/issues/25#issuecomment-36337055), do you confirm? – Val May 18 '15 at 13:21
  • @Val - that does sound like my issue. I ran the command `heroku run bundle exec rake environment elasticsearch:import:model CLASS='Home' FORCE=true` and got the error `Don't know how to build task 'elasticsearch:import:model'` @hirenbhalani thanks for chiming in - I'm new to this so unfortunately i'm not sure how to index the old records. – LarryC May 18 '15 at 13:57
  • @LarryC Good, one step forward. Regarding your latest issue, check this out http://stackoverflow.com/a/26783808/4604579 and shouldn't it be `CLASS='Home'`? – Val May 18 '15 at 14:00
  • @Val, you're right - i corrected the class. Created the file elasticsearch.rake and it contains `namespace :elasticsearch do require 'elasticsearch/rails/tasks/import' end` - unfortunately still getting the same error. – LarryC May 18 '15 at 15:32
  • Can you try to create the index manually (`curl -XPOST http://account.region.bonsai.io/homes`) and see what unfolds? – Val May 18 '15 at 19:42
  • @Val - you're the best. I ran that command, restarted Heroku and now it's working. Thanks so much for your help! – LarryC May 18 '15 at 19:50

1 Answers1

1

The problem is similar to this issue.

The solution involves

  1. running the tasks highlighted here
  2. making sure the elasticsearch.rake exists
  3. and finally if the 404 still happens to create the index manually using curl -XPOST http://account.region.bonsai.io/homes
Community
  • 1
  • 1
Val
  • 207,596
  • 13
  • 358
  • 360