Search code examples
ruby-on-railsherokuelasticsearchsearchkick

How to setup elasticsearch on Heroku?


I've implemented elasticsearch/searchkick on my app and it works on development. My resources for the elasticsearch/searchkick implementation is GoRails and I installed elasticsearch successfully. But when I pushed it on Heroku, it gave me the error:

"We're sorry, but something went wrong."

I did heroku logs and the errors are:

"Completed 500 Internal Server Error in 16ms (Searchkick: 8.0ms | ActiveRecord: 0.0ms)"

and

"Faraday::ConnectionFailed (Connection refused - connect(2) for "localhost" port 9200):"


Solution

  • Please try this .................

    Searchkick uses ENV["ELASTICSEARCH_URL"] for the Elasticsearch server. This defaults to http://localhost:9200.
    Heroku
    

    Choose an add-on: SearchBox, Bonsai, or Elastic Cloud.

    # SearchBox

    heroku addons:create searchbox:starter
    heroku config:set ELASTICSEARCH_URL=`heroku config:get SEARCHBOX_URL`
    

    # Bonsai

    heroku addons:create bonsai
    heroku config:set ELASTICSEARCH_URL=`heroku config:get BONSAI_URL`
    

    # Found

    heroku addons:create foundelasticsearch
    heroku config:set ELASTICSEARCH_URL=`heroku config:get FOUNDELASTICSEARCH_URL`
    

    Then deploy and reindex:

    heroku run rake searchkick:reindex CLASS=Product
    

    Please refer this documentation https://github.com/ankane/searchkick#deployment for more information. Hope this will work for you. Thanks!