Deploying to Heroku, elasticsearch problems

I’ve deployed my app to Heroku however whenever I try to search for a
professor or even view an individual professor (without searching) I
just get “We’re sorry, but something went wrong.”

Running heroku logs returns:

Rendered layouts/_header.html.erb (0.7ms)
2016-06-19T00:10:42.316086+00:00 app[web.1]: Completed 200 OK in 35ms
(Views: 32.3ms | ActiveRecord: 0.9ms)
2016-06-19T00:10:46.924567+00:00 heroku[router]: at=info method=GET
path="/professors/search?utf8=%E2%9C%93&search=test"
host=professor-ratings.herokuapp.com
request_id=a69a87dd-7730-4bbb-a903-e1be1d2d5635 fwd=“198.84.185.123”
dyno=web.1 connect=1ms service=14ms status=500 bytes=1754
2016-06-19T00:10:46.927525+00:00 app[web.1]:
2016-06-19T00:10:46.926535+00:00 app[web.1]: Completed 500 Internal
Server Error in 6ms (ActiveRecord: 0.0ms)
2016-06-19T00:10:46.918438+00:00 app[web.1]: Started GET
“/professors/search?utf8=%E2%9C%93&search=test” for 198.84.185.123 at
2016-06-19 00:10:46 +0000
2016-06-19T00:10:46.927533+00:00 app[web.1]:
app/controllers/professors_controller.rb:35:in `search’
2016-06-19T00:10:46.920628+00:00 app[web.1]: Parameters: {“utf8”=>“✓”,
“search”=>“test”}
2016-06-19T00:10:46.927533+00:00 app[web.1]: Faraday::ConnectionFailed
(Connection refused - connect(2) for “localhost” port 9200):
2016-06-19T00:10:46.927534+00:00 app[web.1]:
2016-06-19T00:10:46.920585+00:00 app[web.1]: Processing by
ProfessorsController#search as HTML
2016-06-19T00:10:46.927534+00:00 app[web.1]:

I’ve seen a similar issue discussed on Stack Overflow and someone said
that elastic search may not be running. But if I run curl
localhost:9200 there is a hash so I believe it’s running and I don’t
think that’s the problem.

Any help would be greatly appreciated I’m very lost this is my first app
I’m building mostly to teach myself rails so I’ve never deployed
anything before.

On 19 June 2016 at 01:53, Travis F. [email protected] wrote:

I’ve deployed my app to Heroku however whenever I try to search for a
professor or even view an individual professor (without searching) I
just get “We’re sorry, but something went wrong.”

If you cannot even view an record then there it is something more than
a search problem. What does the log show when you just try to view?
Always fix the simplest problem first.

Colin

On Sat, Jun 18, 2016 at 5:53 PM, Travis F. [email protected]
wrote:

I’ve deployed my app to Heroku however whenever I try to search for a
professor or even view an individual professor (without searching) I

2016-06-19T00:10:46.920628+00:00 app[web.1]: Parameters: {“utf8”=>“✓”,
“search”=>“test”}
2016-06-19T00:10:46.927533+00:00 app[web.1]: Faraday::ConnectionFailed
(Connection refused - connect(2) for “localhost” port 9200):

I’ve seen a similar issue discussed on Stack Overflow and someone said
that elastic search may not be running. But if I run curl
localhost:9200 there is a hash so I believe it’s running and I don’t
think that’s the problem.

Wait, what?? “localhost” from your development system is not the
same as “localhost” from a Heroku-deployed application.

You need to sign up for a Heroku ElasticSearch add-on or run your
own ES instance somewhere; in either case, the access URL will
certainly not be for “localhost” :slight_smile:


Hassan S. ------------------------ [email protected]
http://about.me/hassanschroeder
twitter: @hassan
Consulting Availability : Silicon Valley or remote

To address the two responses: thank you, I took Colin’s suggestion and
ran a log just trying to access a record:

2016-06-20T23:57:59.062266+00:00 app[web.1]: Completed 500 Internal
Server Error in 10ms (ActiveRecord: 3.5ms)
2016-06-20T23:57:59.061980+00:00 app[web.1]: Rendered
professors/show.html.erb within layouts/application (2.5ms)
2016-06-20T23:57:59.064210+00:00 app[web.1]: ActionView::Template::Error
(undefined method `fullname’ for #Professor:0x007fdd5ef001e8):
2016-06-20T23:57:59.064216+00:00 app[web.1]: 20:


  • Average Review: <div class=“star-rating” data-score=
    <%= @avg_review %>

  • 2016-06-20T23:57:59.064217+00:00 app[web.1]:
    2016-06-20T23:57:59.064214+00:00 app[web.1]: 18:
    2016-06-20T23:57:59.064212+00:00 app[web.1]: 15:
    2016-06-20T23:57:59.064214+00:00 app[web.1]: 17: <%= @professor.fullname %>

    It seems to be having a problem with showing the name, I don’t know why
    this is a problem this page works fine on localhost. One possible thing
    I can think of is that I created a column “firstname” in a recent
    migration (still well before I pushed this to Heroku) could it be
    possible that Postgres is using an earlier migration then SQLite?

    This is my show.hm.erb where the offending method is:

    <%= @professor.fullname %>

    <% end %>
            <li><strong>School: </strong><%= @professor.school %></li>
            <li><strong>Department: </strong>  <%= @professor.department
    

    %>

  • <%= “#{@review.length}” "
    Review".pluralize(@review.length)%>


  • Hassan thanks for the help, I’ll look into this and see if it helps with
    my search problem.

    On 21 June 2016 at 01:09, Travis F. [email protected] wrote:

    2016-06-20T23:57:59.064216+00:00 app[web.1]: 20:


  • It seems to be having a problem with showing the name, I don’t know why
    this is a problem this page works fine on localhost. One possible thing
    I can think of is that I created a column “firstname” in a recent
    migration (still well before I pushed this to Heroku) could it be
    possible that Postgres is using an earlier migration then SQLite?
  • Have a look at the database itself and see. I don’t know how to do
    that on Heroku but I am sure google will tell you if not some
    documentation on Heroku.

    However I note that the error is referring to fullname but you say you
    added a column firstname so perhaps that is the issue.

    Colin

    On Thu, Jun 23, 2016 at 3:07 AM, Travis F. [email protected]
    wrote:

    Elasticsearch still eludes me I’ve been going through this resource:
    https://docs.bonsai.io/docs/ruby-on-rails trying to get bonsai to work I
    get to the last step “Index your documents” but I’m not sure what to put
    for “curl -XPUT
    http://username:[email protected]/users” is it
    just my Heroku username, password and app?

    1. presumably it’s your bonsai account information, but

    2. per the referenced page that’s not the “last step” but only an
      alternative to the preferred setting up of rake tasks.

      What problem(s) are you having with the rake task approach?


    Hassan S. ------------------------ [email protected]
    http://about.me/hassanschroeder
    twitter: @hassan
    Consulting Availability : Silicon Valley or remote

    When ever I try to rake it aborts:

    Starting up a new ElasticSearch client with
    rake aborted!
    NameError: uninitialized constant Elasticsearch::Model

    Elasticsearch is running or at least it seems to be and I did everything
    they said in the Bonsi documentation.

    So the problem displaying the record was indeed because Heroku was on an
    older migration of the DB. So after migrating to the changed column
    names I can access records.

    Elasticsearch still eludes me I’ve been going through this resource:
    https://docs.bonsai.io/docs/ruby-on-rails trying to get bonsai to work I
    get to the last step “Index your documents” but I’m not sure what to put
    for “curl -XPUT
    http://username:[email protected]/users” is it
    just my Heroku username, password and app? Sorry I just can’t find a lot
    of resources to help me deploy Searchkick via Elasticsearch anywhere.

    On Sat, Jun 25, 2016 at 6:26 AM, Travis F. [email protected] wrote:

    When ever I try to rake it aborts:

    Starting up a new ElasticSearch client with
    rake aborted!
    NameError: uninitialized constant Elasticsearch::Model

    Actually, do you have these two entries in your Gemfile?

    gem ‘elasticsearch-rails’
    gem ‘elasticsearch-model’

    If not, add them and run bundle install


    Hassan S. ------------------------ [email protected]
    http://about.me/hassanschroeder
    twitter: @hassan
    Consulting Availability : Silicon Valley or remote

    Hey sorry I have been busy and up until your post I did not have a
    public repo however now I do:

    https://github.com/tfantina/ratings

    I’ve tried to clean it up nicely (when it was private it was a little
    untidy and still is). I have those gems installed but whenever I try to
    load the app in Heroku it crashes:
    Exiting
    2016-06-30T06:51:44.294061+00:00 app[web.1]:
    /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in
    `require’: No such file to load – easticsearch/model (LoadError)

    and now whenever I view the app in localhost it also crashes:

    Started GET “/professors” for ::1 at 2016-06-30 06:01:07 -0400
    Processing by ProfessorsController#index as HTML
    Completed 500 Internal Server Error in 3ms (ActiveRecord: 0.0ms)

    LoadError (cannot load such file – easticsearch/model):

    Thanks again for your help.

    On Thursday, June 30, 2016 at 11:06:48 AM UTC+1, Ruby-Forum.com User
    wrote:

    /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in

    `require’: No such file to load – easticsearch/model (LoadError)

    That looks like you have a typo somewhere in your app - Eastic instead
    of Elastic.

    Fred

    On Sat, Jun 25, 2016 at 6:26 AM, Travis F. [email protected]
    wrote:

    When ever I try to rake it aborts:

    Starting up a new ElasticSearch client with
    rake aborted!
    NameError: uninitialized constant Elasticsearch::Model

    Elasticsearch is running or at least it seems to be

    ? That uninitialized constant error has nothing to do with whether or
    not “Elasticsearch is running”.

    Also, bonsai.io is a service providing an Elasticsearch instance for
    you to connect to; whether you have an instance running locally is
    not relevant.

    Is this project repo public? Or can you create one to demonstrate
    the problem?


    Hassan S. ------------------------ [email protected]
    http://about.me/hassanschroeder
    twitter: @hassan
    Consulting Availability : Silicon Valley or remote

    Thank you so much! I’ve made those changes and pushed them to Github,
    it’s working on my localhost, after work if I have time I’ll try to push
    it to Heroku and see if it works.

    Well I fixed it after much searching on Stack Overflow I realized that I
    needed to create an initializer for it:

    if Rails.env == “production”
    url =
    'elasticsearch hostname ’
    Elasticsearch::Model.client = Elasticsearch::Client.new url: url
    Searchkick.client = Elasticsearch::Client.new(hosts: url,
    retry_on_failure: true, transport_options: {request: {timeout: 250}})
    else
    url = ‘http://localhost:9200/
    Elasticsearch::Model.client = Elasticsearch::Client.new url: url
    Searchkick.client = Elasticsearch::Client.new(hosts: url,
    retry_on_failure: true, transport_options: {request: {timeout: 250}})
    end

    Then I had to reindex the DB and migrate to Heroku.

    On Monday, July 4, 2016 at 6:50:35 PM UTC+1, Ruby-Forum.com User wrote:

    Then I had to reindex the DB and migrate to Heroku. Just to see if it
    would work I copied that code directly from an answer on Stack Overflow
    but now I’m wondering about the AWS url in the if statement, because
    that works for me but I have no idea where that URL is from since I
    don’t personally have an AWS account, is there another more free place
    to host your Elasticsearch? By using this URL am I hijacking someone
    else’s AWS’s account?

    That does look like the the AWS provided elasticsearch hosting service.
    If that URL is part of the copied post, then yes you are using someone
    else’s elasticsearch instance (if you’re feeling helpful you could alert
    whoever posted their data)

    It looks like bonsai.io has a free tier

    Fred

    On 4 July 2016 at 18:50, Travis F. [email protected] wrote:

    url = ‘http://localhost:9200/
    to host your Elasticsearch? By using this URL am I hijacking someone
    else’s AWS’s account?

    Click on the link and you will see what it is pointing to.

    Colin

    This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

    | Privacy Policy | Terms of Service | Remote Ruby Jobs