By default, the client uses a round-robin strategy. You can implement your own strategy by including Elastic::Transport::Transport::Connections::Selector::Base and defining a select method. This allows for advanced logic like rack-awareness.
class RackIdSelector
include Elastic::Transport::Transport::Connections::Selector::Base
def select(options={})
connections.select do |c|
# Try selecting the nodes with a `rack_id:x1` attribute first
c.host[:attributes] && c.host[:attributes][:rack_id] == 'x1'
end.sample || connections.to_a.sample
end
end
Elasticsearch::Client.new hosts: ['x1.search.org', 'x2.search.org'], selector_class: RackIdSelector