Deploying to Heroku, elasticsearch problems.

222 views
Skip to first unread message

Travis Fantina

unread,
Jun 18, 2016, 8:53:36 PM6/18/16
to rubyonra...@googlegroups.com
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.

--
Posted via http://www.ruby-forum.com/.

Colin Law

unread,
Jun 19, 2016, 3:50:21 AM6/19/16
to Ruby on Rails: Talk
On 19 June 2016 at 01:53, Travis Fantina <li...@ruby-forum.com> 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

Hassan Schroeder

unread,
Jun 19, 2016, 10:14:03 AM6/19/16
to rubyonrails-talk
On Sat, Jun 18, 2016 at 5:53 PM, Travis Fantina <li...@ruby-forum.com> 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" :-)

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Consulting Availability : Silicon Valley or remote

Travis Fantina

unread,
Jun 20, 2016, 8:10:14 PM6/20/16
to rubyonra...@googlegroups.com
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: <li>
<strong>Average Review: </strong><div class="star-rating" data-score=
<%= @avg_review %> </div></li>
2016-06-20T23:57:59.064217+00:00 app[web.1]:
2016-06-20T23:57:59.064214+00:00 app[web.1]: 18: <ul
class="list-unstyled">
2016-06-20T23:57:59.064212+00:00 app[web.1]: 15:
2016-06-20T23:57:59.064214+00:00 app[web.1]: 17: <h1
class="review_title"> <%= @professor.fullname %> </h1>


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:

<div class="col-md-6">
<h1 class="review_title"> <%= @professor.fullname %> </h1>
<ul class="list-unstyled">
<% if !@review.blank? %>
<li> <strong>Average Review: </strong><div
class="star-rating" data-score= <%= @avg_review %> </div></li>
<% end %>

<li><strong>School: </strong><%= @professor.school %></li>
<li><strong>Department: </strong> <%= @professor.department
%></li>
<li><%= "#{@review.length}" "
Review".pluralize(@review.length)%></li>
</ul>
</div>

Colin Law

unread,
Jun 21, 2016, 3:20:50 AM6/21/16
to Ruby on Rails: Talk
On 21 June 2016 at 01:09, Travis Fantina <li...@ruby-forum.com> wrote:
> 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: <li>
> <strong>Average Review: </strong><div class="star-rating" data-score=
> <%= @avg_review %> </div></li>
> 2016-06-20T23:57:59.064217+00:00 app[web.1]:
> 2016-06-20T23:57:59.064214+00:00 app[web.1]: 18: <ul
> class="list-unstyled">
> 2016-06-20T23:57:59.064212+00:00 app[web.1]: 15:
> 2016-06-20T23:57:59.064214+00:00 app[web.1]: 17: <h1
> class="review_title"> <%= @professor.fullname %> </h1>
>
>
> 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

Travis Fantina

unread,
Jun 23, 2016, 6:07:47 AM6/23/16
to rubyonra...@googlegroups.com
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:pass...@redwood-12345.us-east-1.bonsai.io/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.

Hassan Schroeder

unread,
Jun 23, 2016, 9:38:23 AM6/23/16
to rubyonrails-talk
On Thu, Jun 23, 2016 at 3:07 AM, Travis Fantina <li...@ruby-forum.com> 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:pass...@redwood-12345.us-east-1.bonsai.io/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?

Travis Fantina

unread,
Jun 25, 2016, 9:27:22 AM6/25/16
to rubyonra...@googlegroups.com
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.

Hassan Schroeder

unread,
Jun 25, 2016, 11:00:04 AM6/25/16
to rubyonrails-talk
On Sat, Jun 25, 2016 at 6:26 AM, Travis Fantina <li...@ruby-forum.com> 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 Schroeder

unread,
Jun 25, 2016, 11:29:46 AM6/25/16
to rubyonrails-talk
> On Sat, Jun 25, 2016 at 6:26 AM, Travis Fantina <li...@ruby-forum.com> 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`

Travis Fantina

unread,
Jun 30, 2016, 6:06:48 AM6/30/16
to rubyonra...@googlegroups.com
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.

Frederick Cheung

unread,
Jun 30, 2016, 7:14:11 AM6/30/16
to Ruby on Rails: Talk
On Thursday, June 30, 2016 at 11:06:48 AM UTC+1, Ruby-Forum.com User wrote:
> 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)
>

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

Fred

Travis Fantina

unread,
Jun 30, 2016, 7:36:03 AM6/30/16
to rubyonra...@googlegroups.com
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.

Travis Fantina

unread,
Jul 4, 2016, 1:50:35 PM7/4/16
to rubyonra...@googlegroups.com
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 =
'https://search-shipit-search-6l6jwr5uhyg5evytk6o3unidya.us-east-1.es.amazonaws.com/'
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. 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?

Colin Law

unread,
Jul 4, 2016, 2:45:55 PM7/4/16
to Ruby on Rails: Talk
Click on the link and you will see what it is pointing to.

Colin

Frederick Cheung

unread,
Jul 6, 2016, 3:25:49 AM7/6/16
to Ruby on Rails: Talk
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

Reply all
Reply to author
Forward
0 new messages