Elastica\Client::updateDocuments PHP Method

updateDocuments() public method

Array of \Elastica\Document as input. Index and type has to be set inside the document, because for bulk settings documents, documents can belong to any type and index
public updateDocuments ( array $docs ) : ResponseSet
$docs array Array of Elastica\Document
return Elastica\Bulk\ResponseSet Response object
    public function updateDocuments(array $docs)
    {
        if (empty($docs)) {
            throw new InvalidException('Array has to consist of at least one element');
        }
        $bulk = new Bulk($this);
        $bulk->addDocuments($docs, \Elastica\Bulk\Action::OP_TYPE_UPDATE);
        return $bulk->send();
    }

Usage Example

 /**
  * @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
     }
 }
All Usage Examples Of Elastica\Client::updateDocuments