如何为 searchkick gem 设置不同的端口?

how to set different port for searchkick gem?

我在 cloud9 的 8081 端口上有 运行 elasticsearch。

/workspace/elasticsearch-6.1.1/bin $ ./elasticsearch -E http.port=8081

然后我在 gem 文件中添加 'searchkick' gem 然后捆绑安装

然后我在模型中添加 searchkick as

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'

这是有道理的,因为它假设弹性搜索服务器 运行ning 在默认的 9200 上,但我 运行 它在 8081 上。我如何告诉 searchkick gem 连接到 8081 端口而不是 9200?感谢您的帮助!谢谢!

创建初始化器config/initializers/elasticsearch.rb:

ENV['ELASTICSEARCH_URL'] = 'http://localhost:8081'

More in official doc