{"action":"opened","issue":{"url":"https://api.github.com/repos/elasticsearch/elasticsearch-ruby/issues/128","labels_url":"https://api.github.com/repos/elasticsearch/elasticsearch-ruby/issues/128/labels{/name}","comments_url":"https://api.github.com/repos/elasticsearch/elasticsearch-ruby/issues/128/comments","events_url":"https://api.github.com/repos/elasticsearch/elasticsearch-ruby/issues/128/events","html_url":"https://github.com/elasticsearch/elasticsearch-ruby/issues/128","id":54564008,"number":128,"title":"Customizing the connection selector","user":{"login":"jlecour","id":5142,"avatar_url":"https://avatars.githubusercontent.com/u/5142?v=3","gravatar_id":"","url":"https://api.github.com/users/jlecour","html_url":"https://github.com/jlecour","followers_url":"https://api.github.com/users/jlecour/followers","following_url":"https://api.github.com/users/jlecour/following{/other_user}","gists_url":"https://api.github.com/users/jlecour/gists{/gist_id}","starred_url":"https://api.github.com/users/jlecour/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlecour/subscriptions","organizations_url":"https://api.github.com/users/jlecour/orgs","repos_url":"https://api.github.com/users/jlecour/repos","events_url":"https://api.github.com/users/jlecour/events{/privacy}","received_events_url":"https://api.github.com/users/jlecour/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-01-16T11:08:20Z","updated_at":"2015-01-16T11:08:20Z","closed_at":null,"body":"Hi,\r\n\r\nI've just found that it's possible to give the ES client a list of hosts (each node in the cluster, for example) and it is able to choose from this list, with a default strategy, that can be swapped.\r\n\r\nIn the README there is even an [example](https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch-transport#connection-selector), but I don't understand how all this deals with unavailable (dead) hosts.\r\n\r\nI've created a very simple selector \r\n\r\n```ruby\r\nclass OrderedSelector\r\n  include Elasticsearch::Transport::Transport::Connections::Selector::Base\r\n\r\n  def select(options={})\r\n    connections.alive.first\r\n  end\r\nend\r\n```\r\n\r\nI would like it to be able to use the first connection in the list that is alive.\r\nWhen the selected host is dead, the client should select the next one.\r\n\r\nLet's say I have this client set-up, with 2 hosts. The host on port `9009` (first in the list) is offline, but the one on `9200` is running.\r\n\r\n```\r\n$ client.transport.connections.alive.map(&:host)\r\n{:host=>\"127.0.0.1\", :port=>\"9209\", :protocol=>\"http\"}, {:host=>\"127.0.0.1\", :port=>\"9200\", :protocol=>\"http\"}]\r\n$ client.cat.indices\r\nNoMethodError: undefined method `host' for nil:NilClass\r\nfrom /Users/jlecour/.gem/ruby/2.1.5/gems/elasticsearch-transport-1.0.6/lib/elasticsearch/transport/transport/base.rb:214:in `rescue in perform_request'\r\n$ client.transport.connections.alive.map(&:host)\r\n{:host=>\"127.0.0.1\", :port=>\"9209\", :protocol=>\"http\"}, {:host=>\"127.0.0.1\", :port=>\"9200\", :protocol=>\"http\"}]\r\n```\r\n\r\nSo the first connection is not removed from the pool.\r\nIn fact I think I don't fully understand how a connection is marked \"dead\".\r\n\r\nI'm quite sure it's not an issue of the library itself, but of my own understanding.\r\n\r\nThanks for any help (here or through documentation)."}}