如何为 searchkick gem 设置不同的端口?
Posted
技术标签:
【中文标题】如何为 searchkick gem 设置不同的端口?【英文标题】:how to set different port for searchkick gem? 【发布时间】:2018-06-09 03:07:28 【问题描述】:我已经在 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?我很感激任何帮助!谢谢!
【问题讨论】:
【参考方案1】:创建一个初始化器config/initializers/elasticsearch.rb
:
ENV['ELASTICSEARCH_URL'] = 'http://localhost:8081'
More in official doc
【讨论】:
以上是关于如何为 searchkick gem 设置不同的端口?的主要内容,如果未能解决你的问题,请参考以下文章
ruby 在Heroku上使用Rails&searchkick gem安全地使用Amazon Elasticsearch(签名请求)。