Heroku Bonsai与宝石'bonsai-elasticsearch-rails'仍然在寻找9200端口

时间:2014-10-07 21:45:57

标签: ruby-on-rails heroku elasticsearch bonsai-elasticsearch

我按照Heroku的说明设置了Bonsai Elasticsearch:

https://devcenter.heroku.com/articles/bonsai

在我的Gemfile中包含所有这些:

gem 'elasticsearch-model'
gem 'elasticsearch-rails'
gem 'bonsai-elasticsearch-rails'

但是,当我运行时仍然出现以下连接错误:

heroku run bundle exec rake environment elasticsearch:import:model CLASS='class' FORCE=true --trace

- - returns - - 

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

Elasticsearch在本地工作,我无法在Heroku上工作。

我的模特是:

class Property < ActiveRecord::Base
  # Search
  Elasticsearch::Model.client = Elasticsearch::Client.new log: true
  include Elasticsearch::Model
  include Elasticsearch::Model::Callbacks

end

Property.import

我有一个rake文件: LIB /任务/ elasticsearch.rake

require 'elasticsearch/rails/tasks/import'

我也在使用Devise,但我认为它不会影响到这一点。在Rails 4.1,Ruby 2.1.2。

有什么建议吗?

**编辑**

我拿出了bonsai-elasticsearch-rails gem并添加了: 配置/初始化/ bonsai.rb

Elasticsearch::Model.client = Elasticsearch::Client.new url: ENV['BONSAI_URL']

仍然遇到同样的错误,寻找端口9200

heroku run bundle exec rake environment elasticsearch:import:model CLASS='Property' FORCE=true --trace
Running `bundle exec rake environment elasticsearch:import:model CLASS=Property FORCE=true --trace` attached to terminal... up, run.8668
** Invoke environment (first_time)
** Execute environment
** Invoke elasticsearch:import:model (first_time)
** Execute elasticsearch:import:model
   (1.5ms)  SELECT COUNT(*) FROM "properties"
2014-10-07 22:39:25 +0000: [Faraday::ConnectionFailed] Connection refused - connect(2) for "localhost" port 9200 {:host=>"localhost", :port=>"9200", :protocol=>"http"}
[!!!] Error when deleting the index: Faraday::ConnectionFailed
Connection refused - connect(2) for "localhost" port 9200
2014-10-07 22:39:25 +0000: [Faraday::ConnectionFailed] Connection refused - connect(2) for "localhost" port 9200 {:host=>"localhost", :port=>"9200", :protocol=>"http"}
2014-10-07 22:39:25 +0000: [Faraday::ConnectionFailed] Connection refused - connect(2) for "localhost" port 9200 {:host=>"localhost", :port=>"9200", :protocol=>"http"}
[!!!] Error when creating the index: Faraday::ConnectionFailed
Connection refused - connect(2) for "localhost" port 9200
  Property Load (1.8ms)  SELECT  "properties".* FROM "properties"   ORDER BY "properties"."id" ASC LIMIT 1000
2014-10-07 22:39:25 +0000: [Faraday::ConnectionFailed] Connection refused - connect(2) for "localhost" port 9200 {:host=>"localhost", :port=>"9200", :protocol=>"http"}
rake aborted!
Faraday::ConnectionFailed: Connection refused - connect(2) for "localhost" port 9200
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/net/http.rb:879:in `initialize'
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/net/http.rb:879:in `open'
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/net/http.rb:879:in `block in connect'
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/timeout.rb:76:in `timeout'
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/net/http.rb:878:in `connect'
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/net/http.rb:863:in `do_start'
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/net/http.rb:852:in `start'
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/net/http.rb:1369:in `request'
/app/vendor/bundle/ruby/2.1.0/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:80:in `perform_request'
/app/vendor/bundle/ruby/2.1.0/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:39:in `call'
/app/vendor/bundle/ruby/2.1.0/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:139:in `build_response'
/app/vendor/bundle/ruby/2.1.0/gems/faraday-0.9.0/lib/faraday/connection.rb:377:in `run_request'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-transport-1.0.5/lib/elasticsearch/transport/transport/http/faraday.rb:21:in `block in perform_request'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-transport-1.0.5/lib/elasticsearch/transport/transport/base.rb:187:in `call'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-transport-1.0.5/lib/elasticsearch/transport/transport/base.rb:187:in `perform_request'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-transport-1.0.5/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-transport-1.0.5/lib/elasticsearch/transport/client.rb:104:in `perform_request'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-api-1.0.5/lib/elasticsearch/api/actions/bulk.rb:81:in `bulk'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-model-0.1.6/lib/elasticsearch/model/importing.rb:120:in `block in import'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-model-0.1.6/lib/elasticsearch/model/adapters/active_record.rb:96:in `block in __find_in_batches'
/app/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.4/lib/active_record/relation/batches.rb:125:in `find_in_batches'
/app/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.4/lib/active_record/querying.rb:9:in `find_in_batches'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-model-0.1.6/lib/elasticsearch/model/proxy.rb:80:in `method_missing'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-model-0.1.6/lib/elasticsearch/model/adapters/active_record.rb:95:in `__find_in_batches'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-model-0.1.6/lib/elasticsearch/model/importing.rb:119:in `import'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-rails-0.1.6/lib/elasticsearch/rails/tasks/import.rb:63:in `block (3 levels) in <top (required)>'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:240:in `call'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:240:in `block in execute'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:235:in `each'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:235:in `execute'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:165:in `invoke'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:150:in `invoke_task'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `each'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `block in top_level'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:115:in `run_with_threads'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:100:in `top_level'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:78:in `block in run'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/bin/rake:33:in `<top (required)>'
/app/vendor/bundle/ruby/2.1.0/bin/rake:23:in `load'
/app/vendor/bundle/ruby/2.1.0/bin/rake:23:in `<main>'
Errno::ECONNREFUSED: Connection refused - connect(2) for "localhost" port 9200
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/net/http.rb:879:in `initialize'
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/net/http.rb:879:in `open'
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/net/http.rb:879:in `block in connect'
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/timeout.rb:76:in `timeout'
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/net/http.rb:878:in `connect'
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/net/http.rb:863:in `do_start'
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/net/http.rb:852:in `start'
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/net/http.rb:1369:in `request'
/app/vendor/bundle/ruby/2.1.0/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:80:in `perform_request'
/app/vendor/bundle/ruby/2.1.0/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:39:in `call'
/app/vendor/bundle/ruby/2.1.0/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:139:in `build_response'
/app/vendor/bundle/ruby/2.1.0/gems/faraday-0.9.0/lib/faraday/connection.rb:377:in `run_request'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-transport-1.0.5/lib/elasticsearch/transport/transport/http/faraday.rb:21:in `block in perform_request'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-transport-1.0.5/lib/elasticsearch/transport/transport/base.rb:187:in `call'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-transport-1.0.5/lib/elasticsearch/transport/transport/base.rb:187:in `perform_request'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-transport-1.0.5/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-transport-1.0.5/lib/elasticsearch/transport/client.rb:104:in `perform_request'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-api-1.0.5/lib/elasticsearch/api/actions/bulk.rb:81:in `bulk'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-model-0.1.6/lib/elasticsearch/model/importing.rb:120:in `block in import'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-model-0.1.6/lib/elasticsearch/model/adapters/active_record.rb:96:in `block in __find_in_batches'
/app/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.4/lib/active_record/relation/batches.rb:125:in `find_in_batches'
/app/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.4/lib/active_record/querying.rb:9:in `find_in_batches'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-model-0.1.6/lib/elasticsearch/model/proxy.rb:80:in `method_missing'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-model-0.1.6/lib/elasticsearch/model/adapters/active_record.rb:95:in `__find_in_batches'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-model-0.1.6/lib/elasticsearch/model/importing.rb:119:in `import'
/app/vendor/bundle/ruby/2.1.0/gems/elasticsearch-rails-0.1.6/lib/elasticsearch/rails/tasks/import.rb:63:in `block (3 levels) in <top (required)>'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:240:in `call'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:240:in `block in execute'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:235:in `each'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:235:in `execute'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:165:in `invoke'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:150:in `invoke_task'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `each'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `block in top_level'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:115:in `run_with_threads'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:100:in `top_level'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:78:in `block in run'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
/app/vendor/bundle/ruby/2.1.0/gems/rake-10.3.2/bin/rake:33:in `<top (required)>'
/app/vendor/bundle/ruby/2.1.0/bin/rake:23:in `load'
/app/vendor/bundle/ruby/2.1.0/bin/rake:23:in `<main>'
Tasks: TOP => elasticsearch:import:model

**编辑2 **

使用相同的错误:

elasticsearch-model 0.1.4 or 0.1.6
elasticsearch-rails 0.1.4 or 0.1.6

2 个答案:

答案 0 :(得分:4)

在我的模型中发现这一行是覆盖其他设置:

Elasticsearch::Model.client = Elasticsearch::Client.new log: true

如果我将其设置为此错误就会消失:

Elasticsearch::Model.client = Elasticsearch::Client.new url: ENV['BONSAI_URL'], log: true

感谢Nick和Rob帮助我。现在转到下一个错误...

**更新12-29-2014 我遇到了从新安装运行此错误的相同错误,通过键入

修复了它
$ elasticsearch

在控制台中启动elasticsearch。希望这有助于其他人。

答案 1 :(得分:0)

我做了:

/etc/init.d/elasticsearch restart

它为我解决了这个问题。