Class: Elastics::Client::Bulk::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/elastics/client/bulk.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



15
16
17
# File 'lib/elastics/client/bulk.rb', line 15

def initialize
  @actions = []
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



13
14
15
# File 'lib/elastics/client/bulk.rb', line 13

def actions
  @actions
end

Instance Method Details

#add_action(action, params, data = nil) ⇒ Object



27
28
29
30
31
# File 'lib/elastics/client/bulk.rb', line 27

def add_action(action, params, data = nil)
  params = {_id: params} unless params.is_a?(Hash)
  @actions << {action => params}
  @actions << data if data
end

#any?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/elastics/client/bulk.rb', line 19

def any?
  @actions.any?
end

#bodyObject



23
24
25
# File 'lib/elastics/client/bulk.rb', line 23

def body
  @actions.map(&:to_json).join("\n".freeze) + "\n"
end

#delete(params) ⇒ Object



43
44
45
# File 'lib/elastics/client/bulk.rb', line 43

def delete(params)
  add_action(:delete, params)
end

#update_doc(params, fields) ⇒ Object



39
40
41
# File 'lib/elastics/client/bulk.rb', line 39

def update_doc(params, fields)
  update(params, doc: fields)
end