Skip to content

Commit 9145988

Browse files
committed
Implement support for update and delete actions in the Bulk API
1 parent 6d5842f commit 9145988

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

src/Classes/Bulk.php

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,26 +125,59 @@ public function id($_id = false)
125125
}
126126

127127
/**
128-
* Add pending document
128+
* Add pending document for insert
129129
* @param array $data
130130
*/
131131
public function insert($data = [])
132132
{
133133

134+
$this->action('index', $data);
135+
136+
}
137+
138+
/**
139+
* Add pending document for update
140+
* @param array $data
141+
*/
142+
public function update($data = [])
143+
{
144+
145+
$this->action('update', $data);
146+
147+
}
148+
149+
/**
150+
* Add pending document for deletion
151+
*/
152+
public function delete()
153+
{
154+
155+
$this->action('delete');
156+
157+
}
158+
159+
/**
160+
* Add pending document abstract action
161+
* @param string $actionType
162+
* @param array $data
163+
*/
164+
public function action($actionType, $data = [])
165+
{
134166
$this->body["body"][] = [
135167

136-
'index' => [
168+
$actionType => [
137169
'_index' => $this->getIndex(),
138170
'_type' => $this->getType(),
139171
'_id' => $this->_id
140172
]
141173

142174
];
143175

144-
$this->body["body"][] = $data;
176+
if (!empty($data)) {
177+
$this->body["body"][] = $data;
178+
}
145179

146180
$this->reset();
147-
148181
}
149182

150183
/**

0 commit comments

Comments
 (0)