Class: ElasticSearch::Transport::HTTP

Inherits:
Base
  • Object
show all
Defined in:
lib/elasticsearch/transport/http.rb

Constant Summary collapse

DEFAULTS =
{
  :timeout => 5,
  :protocol => 'http'
}.freeze

Instance Attribute Summary collapse

Attributes inherited from Base

#options, #server

Instance Method Summary collapse

Methods inherited from Base

#close, #encoder

Methods included from ClusterAdminProtocol

#cluster_health, #cluster_state, #nodes_info, #nodes_stats, #restart_nodes, #shutdown_nodes

Methods included from IndexAdminProtocol

#alias_index, #create_index, #create_river, #delete_index, #delete_mapping, #delete_river, #flush, #get_aliases, #get_river, #get_settings, #index_mapping, #index_status, #optimize, #refresh, #river_status, #snapshot, #update_mapping, #update_settings

Methods included from IndexProtocol

#bulk, #count, #delete, #delete_by_query, #get, #index, #multi_get, #scroll, #search

Constructor Details

#initialize(server, options = {}, &block) ⇒ HTTP

Returns a new instance of HTTP.



14
15
16
17
18
19
20
21
22
23
# File 'lib/elasticsearch/transport/http.rb', line 14

def initialize(server, options={}, &block)
  super
  @options = DEFAULTS.merge(@options)
  @connect_block = block if block_given?

  # Make sure the server starts with a URI scheme.
  unless @server =~ /^(([^:\/?#]+):)?\/\//
    @server = "#{@options[:protocol]}://" + @server
  end
end

Instance Attribute Details

#sessionObject

Returns the value of attribute session.



12
13
14
# File 'lib/elasticsearch/transport/http.rb', line 12

def session
  @session
end

Instance Method Details

#all_nodesObject



34
35
36
37
38
39
40
41
42
# File 'lib/elasticsearch/transport/http.rb', line 34

def all_nodes
  http_addresses = nodes_info([])["nodes"].collect { |id, node| node["http_address"] }
  http_addresses.collect! do |a|
    if a =~ /inet\[.*\/([\d.:]+)\]/
      $1
    end
  end.compact!
  http_addresses
end

#connect!Object



25
26
27
28
29
30
31
32
# File 'lib/elasticsearch/transport/http.rb', line 25

def connect!
  if @connect_block
    @session = Faraday.new :url => @server, &@connect_block
  else
    @session = Faraday.new :url => @server
  end
  @session.options[:timeout] = @options[:timeout]
end