AWS elasticsearch服务引发Faraday :: ConnectionFailed:无法打开与https:80的TCP连接(getaddrinfo:名称或服务未知)

时间:2018-11-05 20:55:12

标签: ruby-on-rails amazon-web-services elasticsearch

我目前正在尝试在Rails v 5.1.4应用程序中配置AWS的Elasticsearch服务。我正在使用elasticsearch-rails 6.0.0.,我目前所相信的问题是如何在初始化程序中设置我的Elasticsearch客户端。我的一个限制是我无法使用faraday_middleware-aws-signers-v4 gem来帮助我的AWS elastisearch实例与我的应用程序之间的通信。我尝试仅使用aws-sdk-rails 1.0.1.来执行此操作,因为该服务器与Elasticsearch实例位于同一安全组中,所以我假设不需要传递凭据。

这是我的错误:

Faraday::ConnectionFailed: Failed to open TCP connection to https:80 (getaddrinfo: Name or service not known)
from /usr/local/lib/ruby/2.4.0/net/http.rb:906:in `rescue in block in connect'`

这是我的initializers/elasticsearch.rb

config = {
  hosts: {host: 'https://search-epl-elasticsearch-xxxxxxxxxxxxxxxxxx.us-east-2.es.amazonaws.com', port: '80'},
  transport_options: {
    request: { timeout: 5 }
  }
}
Elasticsearch::Model.client = Elasticsearch::Client.new(config)

1 个答案:

答案 0 :(得分:1)

我知道已经过了几个月,但是看来您正在使用https url配置elasticsearch并告诉它使用端口80而不是443。请尝试以下操作:

config = {
  url: 'https://search-epl-elasticsearch-xxxxxxxxxxxxxxxxxx.us-east-2.es.amazonaws.com',
  transport_options: {
    request: { timeout: 5 }
  }
}
Elasticsearch::Model.client = Elasticsearch::Client.new(config)