elastic / elasticsearch-ruby

Ruby integrations for Elasticsearch
https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/index.html
Apache License 2.0
1.97k stars 597 forks source link

Very unreliable connection #244

Closed ponny closed 8 years ago

ponny commented 8 years ago

I seem to be getting errors about half the time when using the service. My Internet connection is fine and I'm pretty sure that Amazon ES actually works (I've got two nodes and it's been green status the whole time) so I suspect I've got a configuration issue.

[Faraday::TimeoutError] Operation timed out after 0 milliseconds with 0 out of 0 bytes received {:scheme=>"https", :user=>nil, :password=>nil, :host=>"[removed].us-west-2.es.amazonaws.com", :path=>"", :port=>443, :protocol=>"https"}

I'm setting my connection as such:

    Elasticsearch::Client.new(url: "https://[removed].us-west-2.es.amazonaws.com", log: true) do |f|
      f.request :aws_signers_v4,
                credentials: Aws::Credentials.new(access_key_id, secret_access_key),
                service_name: 'es',
                region: 'us-west-2'
    end
AaronRustad commented 8 years ago

Your error seems to suggest that you somehow have a 0 second timeout.... consider setting it... here's something that worked quite well for me for the last week or so.

require 'elasticsearch'
require 'elasticsearch/model'
require 'faraday_middleware/aws_signers_v4'

es_servers = Array(ENV.fetch('ELASTICSEARCH_URL', AppConfig.es_hosts))
config = {
             hosts: es_servers,
            logger: ActiveSupport::Logger.new("#{Rails.root}/log/elasticsearch.log"),
  retry_on_failure: true,
   request_timeout: 5
}

case Rails.env
when 'development', 'staging'
  config.merge!(trace: true) unless 'rake' == File.basename($0)
end

Elasticsearch::Model.client =
  Elasticsearch::Client.new(config) do |f|
    if Rails.env.production?
      # We should be able to remove this once we move into the VPC
      f.request(:aws_signers_v4, credentials: Aws::Credentials.new(AppConfig.aws_access_key_id, AppConfig.aws_s3_secret_access_key), service_name: 'es', region: 'us-east-1')
    end
  end
ponny commented 8 years ago

Tried it. No change. Here's my config:

      f.request :aws_signers_v4,
                credentials: Aws::Credentials.new(access_key_id, secret_access_key),
                service_name: 'es',
                region: 'us-west-2',
                retry_on_failure: true,
                request_timeout: 5
ponny commented 8 years ago

Found the problem. I had to set it on the Elasticsearch::Client.new, not the inner request. Thanks.