我在cloud9上的端口8081上运行了elasticsearch。
/workspace/elasticsearch-6.1.1/bin $ ./elasticsearch -E http.port=8081
然后我在gemfile中添加'searchkick'gem,然后捆绑安装
然后我将模型中的searchkick添加为
class Book < ActiveRecord::Base
searchkick
end
然后我运行命令
Book.reindex
我收到以下错误
2.3.4 :001 > Book.reindex
Faraday::ConnectionFailed: Failed to open TCP connection to localhost:9200 (Connection refused - connect(2) for "localhost" port 9200)
from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/net/http.rb:882:in `rescue in block in connect'
from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/net/http.rb:879:in `block in connect'
from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout'
from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/net/http.rb:878:in `connect'
from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/net/http.rb:852:in `start'
这是有道理的,因为它假设弹性搜索服务器在默认的9200上运行,但我在8081上运行它。我怎么告诉searchkick gem连接到8081端口而不是9200?我感谢任何帮助!谢谢!
答案 0 :(得分:2)
创建初始值设定项config/initializers/elasticsearch.rb
:
ENV['ELASTICSEARCH_URL'] = 'http://localhost:8081'