diff --git a/elasticsearch-transport/lib/elasticsearch/transport/client.rb b/elasticsearch-transport/lib/elasticsearch/transport/client.rb index 1d033d82ea..be61a6d54b 100644 --- a/elasticsearch-transport/lib/elasticsearch/transport/client.rb +++ b/elasticsearch-transport/lib/elasticsearch/transport/client.rb @@ -142,10 +142,8 @@ def initialize(arguments={}, &block) transport_class = @arguments[:transport_class] || DEFAULT_TRANSPORT_CLASS if transport_class == Transport::HTTP::Faraday @transport = transport_class.new(hosts: @seeds, options: @arguments) do |faraday| - block.call faraday if block - unless (h = faraday.builder.handlers.last) && h.name.start_with?("Faraday::Adapter") - faraday.adapter(@arguments[:adapter] || __auto_detect_adapter) - end + faraday.adapter(@arguments[:adapter] || __auto_detect_adapter) + block&.call faraday end else @transport = transport_class.new(hosts: @seeds, options: @arguments)