Class: Elasticity::Bulk

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

Direct Known Subclasses

Alias, Index

Defined Under Namespace

Classes: Alias, Index

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Bulk

Returns a new instance of Bulk.



3
4
5
6
# File 'lib/elasticity/bulk.rb', line 3

def initialize(client)
  @client     = client
  @operations = []
end

Instance Method Details

#delete(index_name, id) ⇒ Object



16
17
18
# File 'lib/elasticity/bulk.rb', line 16

def delete(index_name, id)
  @operations << { delete: { _index: index_name, _id: id }}
end

#executeObject



20
21
22
# File 'lib/elasticity/bulk.rb', line 20

def execute
  @client.bulk(body: @operations)
end

#index(index_name, id, attributes) ⇒ Object



8
9
10
# File 'lib/elasticity/bulk.rb', line 8

def index(index_name, id, attributes)
  @operations << { index: { _index: index_name, _id: id, data: attributes }}
end

#update(index_name, id, attributes) ⇒ Object



12
13
14
# File 'lib/elasticity/bulk.rb', line 12

def update(index_name, id, attributes)
  @operations << { update: { _index: index_name, _id: id, data: attributes }}
end