/**
* @param Document[] $documents
* @param Closure $errorHandler
*/
protected function batchUpdate(array $documents, Closure $errorHandler)
{
$count = count($documents);
if ($count === 0) {
return;
}
if ($this->verbose) {
array_map(function (Document $document) {
$data = $document->getData();
dump($data);
}, $documents);
}
$this->validateFields($documents);
try {
$responseSet = $this->elastica->updateDocuments($documents);
$failedSnsidList = [];
$versionList = [];
foreach ($responseSet as $response) {
$this->parseResponse($response, $failedSnsidList, $versionList);
}
if ($failedSnsidList) {
call_user_func($errorHandler, $failedSnsidList);
}
if (is_callable($this->versionHandler)) {
call_user_func($this->versionHandler, $versionList);
}
} catch (\Exception $exception) {
if (is_callable($this->errorHandler)) {
call_user_func($this->errorHandler, $exception);
}
$this->elastica = $this->makeElastica();
// Try to keep going on updating
}
}