Elastica\Client::addDocuments PHP Method

addDocuments() 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 addDocuments ( array $docs ) : ResponseSet
$docs array Array of Elastica\Document
return Elastica\Bulk\ResponseSet Response object
    public function addDocuments(array $docs)
    {
        if (empty($docs)) {
            throw new InvalidException('Array has to consist of at least one element');
        }
        $bulk = new Bulk($this);
        $bulk->addDocuments($docs);
        return $bulk->send();
    }

Usage Example

 /**
  * Use Elasticsearch bulk API to send list of documents
  * @param  array $documents
  * @throws \RuntimeException
  */
 protected function bulkSend(array $documents)
 {
     try {
         $this->client->addDocuments($documents);
     } catch (ExceptionInterface $e) {
         if (!$this->options['ignore_error']) {
             throw new \RuntimeException("Error sending messages to Elasticsearch", 0, $e);
         }
     }
 }
All Usage Examples Of Elastica\Client::addDocuments