class ElasticSearch::IndexRequest

Public Class Methods

new(client, index, type, id=nil, data={}) click to toggle source

Create a new index request.

Calls superclass method ElasticSearch::Request::new
# File lib/jruby-elasticsearch/indexrequest.rb, line 6
def initialize(client, index, type, id=nil, data={})
  @client = client
  @index = index
  @type = type
  @id = id
  @data = data

  # This should silence jruby warnings for 'multiple java methods for prepareIndex'
  if id.nil?
    @prep = @client.prepareIndex(index, type)
  else
    @prep = @client.prepareIndex(index, type, id)
  end
  super()
end

Public Instance Methods

execute(&block) click to toggle source

Execute this index request. This call is asynchronous.

If a block is given, register it for both failure and success.

# File lib/jruby-elasticsearch/indexrequest.rb, line 26
def execute(&block)
  @prep.setSource(@data)
  use_callback(&block) if block_given?

  action = @prep.execute(@handler)
  return action
end
execute!() click to toggle source

Execute this index request synchronously

# File lib/jruby-elasticsearch/indexrequest.rb, line 35
def execute!
  @prep.setSource(@data)
  return @prep.execute.actionGet()
end
method_missing(*args) click to toggle source

DSL helper. TODO(sissel): Move this away to a DSL module.

# File lib/jruby-elasticsearch/indexrequest.rb, line 42
def method_missing(*args)
  key, value = args
  puts "Adding: #{key}: #{value.inspect}"
  @data[key.to_s] = value
end