Rails app crashes after deploying ElasticSearch implementation to Heroku

Hi, I just implemented ElasticSearch to my Rails app with the help of this blogpost: Full-Text Search in Rails with ElasticSearch

Locally on my dev maching everything works fine, but on Heroku, the application crashed:

http://morning-anchorage-2469.herokuapp.com/

I tried to solve the issue by installing the Heroku add-on, bonsai-elasticsearch but that didn’t solve it.

The Heroku logs don’t make me much wiser either:

from bin/rails:8:in `require'
2014-08-14T12:51:12.352016+00:00 app[web.1]: 	from bin/rails:8:in `<main>'
2014-08-14T12:51:13.470645+00:00 heroku[web.1]: State changed from starting to crashed
2014-08-14T12:51:13.447331+00:00 heroku[web.1]: Process exited with status 1
2014-08-14T13:25:30.971800+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET     path="/" host=morning-anchorage-2469.herokuapp.com request_id=353c4170-531c-4ff1-9afd-4975169e5176 fwd="81.245.163.54" dyno= connect= service= status=503 bytes=
2014-08-14T13:25:31.401546+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET   path="/favicon.ico" host=morning-anchorage-2469.herokuapp.com request_id=a42774ab-930a-4c8b-81d4-bf1c91617f1e fwd="81.245.163.54" dyno= connect= service= status=503 bytes=
2014-08-14T13:32:01.917187+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=morning-anchorage-2469.herokuapp.com request_id=66c4cbfb-79ef-4d97-b297-b50d2595b284 fwd="81.245.163.54" dyno= connect= service= status=503 bytes=
2014-08-14T13:32:02.368129+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=morning-anchorage-2469.herokuapp.com request_id=19aabd8d-7b97-4a2c-b824-d2ae8ea19aed fwd="81.245.163.54" dyno= connect= service= status=503 bytes=

Did I miss something?

my repository is at: https://github.com/acandael/posplus-rails

thanks for your help, advice,

Anthony

It looks like you didn’t hook your app up to Bonsai, so the app is likely crashing because it’s not finding any ElasticSearch to talk to. You need to follow the instructions for the Bonsai addon and use BONSAI_URL to attach to Bonsai’s server:

Hi Geoff,

When I run

heroku config | grep BONSAI

I get:

BONSAI_URL:                  https://9usk3dda:m6p46lanqqo4wizo@dogwood-5626701.us-east-1.bonsai.io

Does that mean that Bonsai is hooked up? I did install Bonsai with:

heroku addons:add bonsai

I also have access to the Bonsai-ElasticSearch Dashboard.

Howerver when I run:

heroku run rails c

I get this output:

Running `rails c` attached to terminal... up, run.2837
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:878:in `initialize': Connection refused - connect(2) (Faraday::ConnectionFailed)
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:878:in `open'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:878:in `block in connect'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/timeout.rb:52:in `timeout'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:877:in `connect'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:851:in `start'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:1367:in `request'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:80:in `perform_request'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:39:in `call'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:139:in `build_response'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday-0.9.0/lib/faraday/connection.rb:377:in `run_request'
from /app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.4/lib/elasticsearch/transport/transport/http/faraday.rb:21:in `block in perform_request'
from /app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.4/lib/elasticsearch/transport/transport/base.rb:187:in `call'
from /app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.4/lib/elasticsearch/transport/transport/base.rb:187:in `perform_request'
from /app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.4/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
from /app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.4/lib/elasticsearch/transport/client.rb:102:in `perform_request'
from /app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-api-1.0.4/lib/elasticsearch/api/namespace/common.rb:21:in `perform_request'
from /app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-api-1.0.4/lib/elasticsearch/api/actions/indices/create.rb:77:in `create'
from /app/app/models/publication.rb:67:in `<top (required)>'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `block in require'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:348:in `require_or_load'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:307:in `depend_on'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:225:in `require_dependency'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:468:in `block (2 levels) in eager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:467:in `each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:467:in `block in eager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:465:in `each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:465:in `eager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:346:in `eager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/application/finisher.rb:58:in `each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/application/finisher.rb:58:in `block in <module:Finisher>'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:30:in `instance_exec'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:30:in `run'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:55:in `block in run_initializers'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:180:in `each'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:54:in `run_initializers'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/application.rb:288:in `initialize!'
from /app/config/environment.rb:5:in `<top (required)>'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/application.rb:264:in `require'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/application.rb:264:in `require_environment!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:147:in `require_application_and_environment!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:68:in `console'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
from /app/bin/rails:8:in `require'
from /app/bin/rails:8:in `<main>'

reading over the Heroku documentation, I’m seeing this:

Our free plan for development and testing allows a single index with one shard, and no replication. 
...

Does that mean I can only do a search on 1 model? Because I do a search on 2 models

You need to build an initializer like the documentation subscribes (look for the part where it describes a file in config/initializers, you can’t just cherry-pick from these docs, you have to follow them step-by-step in order to get the add-on to work). I figured out you weren’t properly hooked up because you didn’t reference the BONSAI_URL line in your code base anywhere.

As for whether you have to pay: looks like it. Folks don’t provide service for other people without hoping to get something in return! Maybe you can start with one model and then verify it works before signing up for a paid plan.

1 Like

At the moment it’s not really clear to me if I need to user Tire on Heroku, because, localy my Rails app doesn’t use Tire.

I’m using these gems:

gem 'elasticsearch-model', '~> 0.1.4'
gem 'elasticsearch-rails', '~> 0.1.4'

I’ve contacted the Bonsai support team hoping they can enlighten me in this matter.

thanks for your help,

Anthony

phew, it’s fixed. I got some help from the Bonsai add-on support.

Seemed that I needed to add:

ENV['ELASTICSEARCH_URL'] = ENV['BONSAI_URL']

to config/initializers/bonzai.rb

But I also needed to add

gem 'bonsai-elasticsearch-rails'

to my Gemfile.

Seems I’m not the only one who encountered this problem: ruby on rails - Connection Refused Error Trying to Import ElasticSearch Model through Rake on Heroku - Stack Overflow

glad it’s solved : )