class Wukong::Load::ElasticsearchLoader

Loads data into Elasticsearch.

Uses Elasticsearch's HTTP API to communicate.

Allows loading records into a given index and type. Records can have fields `_index` and `_es_type` which override the given index and type on a per-record basis.

Records can have an `_id` field which indicates an update, not a create.

The names of these fields within each record (`_index`, `_es_type`, and `_id`) can be customized.

Attributes

connection[RW]

The Net::HTTP connection we'll use for talking to Elasticsearch.

Public Instance Methods

load(record) click to toggle source

Load a single record into Elasticsearch.

If the record has an ID, we'll issue an update, otherwise a create

@param [Hash] record

# File lib/wukong-load/loaders/elasticsearch.rb, line 71
def load record
  id_for(record) ? request(Net::HTTP::Put, update_path(record), record) : request(Net::HTTP::Post, create_path(record), record)
end
setup() click to toggle source

Creates a connection

# File lib/wukong-load/loaders/elasticsearch.rb, line 55
def setup
  h = host.gsub(%r{^http://},'')
  log.debug("Connecting to Elasticsearch cluster at #{h}:#{port}...")
  begin
    self.connection = Net::HTTP.new(h, port)
    self.connection.use_ssl = true if host =~ /^https/
  rescue => e
    raise Error.new(e.message)
  end
end