class ElasticSearch::AbstractClient
Constants
- DEFAULTS
Attributes
connection[RW]
current_server[RW]
servers[RW]
Public Class Methods
new(servers_or_url, options={}, &block)
click to toggle source
# File lib/elasticsearch/client/abstract_client.rb, line 12 def initialize(servers_or_url, options={}, &block) @options = DEFAULTS.merge(options) @servers, @default_index, @default_type = extract_servers_and_defaults(servers_or_url) @current_server = @servers.first @connect_block = block end
Public Instance Methods
connect!()
click to toggle source
# File lib/elasticsearch/client/abstract_client.rb, line 35 def connect! if @options[:transport].is_a?(Class) if @connect_block @connection = @options[:transport].new(@current_server, @options, &@connect_block) else @connection = @options[:transport].new(@current_server, @options) end else @connection = @options[:transport] end @connection.connect! end
disconnect!()
click to toggle source
# File lib/elasticsearch/client/abstract_client.rb, line 48 def disconnect! @connection.close rescue nil @connection = nil @current_server = nil end
execute(method_name, *args)
click to toggle source
# File lib/elasticsearch/client/abstract_client.rb, line 54 def execute(method_name, *args) connect! unless @connection @connection.send(method_name, *args) end
extract_servers_and_defaults(servers_or_url)
click to toggle source
# File lib/elasticsearch/client/abstract_client.rb, line 19 def extract_servers_and_defaults(servers_or_url) default_index = default_type = nil given_servers = Array(servers_or_url).collect do |server| begin uri = URI.parse(server) raise URI::InvalidURIError, server if uri.path.nil? _, default_index, default_type = uri.path.split("/") uri.path = "" # is this expected behavior of URI? may be dangerous to rely on uri.to_s rescue URI::InvalidURIError server end end [given_servers, default_index, default_type] end