Class: ElasticSearch::BulkRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/jruby-elasticsearch/bulkrequest.rb

Instance Method Summary collapse

Methods inherited from Request

#on, #use_callback

Constructor Details

#initialize(client) ⇒ BulkRequest

Returns a new instance of BulkRequest.



7
8
9
10
11
# File 'lib/jruby-elasticsearch/bulkrequest.rb', line 7

def initialize(client)
  @client = client
  @prep = @client.prepareBulk()
  super()
end

Instance Method Details

#<<(request) ⇒ Object



40
41
42
# File 'lib/jruby-elasticsearch/bulkrequest.rb', line 40

def <<(request)
  @prep.add(request)
end

#execute(&block) ⇒ Object

Execute this index request. This call is asynchronous.

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



17
18
19
20
21
# File 'lib/jruby-elasticsearch/bulkrequest.rb', line 17

def execute(&block)
  use_callback(&block) if block_given?
  action = @prep.execute(@handler)
  return action
end

#execute!Object



25
26
27
# File 'lib/jruby-elasticsearch/bulkrequest.rb', line 25

def execute!
  return @prep.execute.actionGet()
end

#index(index, type, id = nil, data = {}) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/jruby-elasticsearch/bulkrequest.rb', line 31

def index(index, type, id=nil, data={})
  req = org.elasticsearch.action.index.IndexRequest.new(index)
  req.type(type) if type
  req.id(id.to_s) if id
  req.source(data)
  @prep.add(req)
end