Class: ElasticSearch::AbstractClient

Inherits:
Object
  • Object
show all
Defined in:
lib/elasticsearch/client/abstract_client.rb

Direct Known Subclasses

Client

Constant Summary collapse

DEFAULTS =
{
  :transport => ElasticSearch::Transport::HTTP
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(servers, options = {}) ⇒ AbstractClient

Returns a new instance of AbstractClient.



8
9
10
11
12
# File 'lib/elasticsearch/client/abstract_client.rb', line 8

def initialize(servers, options={})
  @options = DEFAULTS.merge(options)
  @server_list = Array(servers)
  @current_server = @server_list.first
end

Instance Method Details

#connect!Object



18
19
20
21
# File 'lib/elasticsearch/client/abstract_client.rb', line 18

def connect!
  @connection = @options[:transport].new(@current_server, @options)
  @connection.connect!
end

#disconnect!Object



23
24
25
26
27
# File 'lib/elasticsearch/client/abstract_client.rb', line 23

def disconnect!
  @connection.close rescue nil
  @connection = nil
  @current_server = nil
end

#execute(method_name, *args) ⇒ Object



29
30
31
32
# File 'lib/elasticsearch/client/abstract_client.rb', line 29

def execute(method_name, *args)
  connect! unless @connection
  @connection.send(method_name, *args)
end

#inspectObject



14
15
16
# File 'lib/elasticsearch/client/abstract_client.rb', line 14

def inspect
  "<#{self.class} @current_server=#{@current_server} @server_list=#{@server_list.inspect} @options=#{@options.inspect}>"
end