eZ\Publish\Core\Search\Elasticsearch\Content\Gateway\Native::bulkIndex PHP Method

bulkIndex() public method

Performs bulk index of a given array of documents.
public bulkIndex ( array $documents )
$documents array
    public function bulkIndex(array $documents)
    {
        if (empty($documents)) {
            return;
        }
        $payload = '';
        foreach ($documents as $document) {
            $payload .= $this->serializer->getIndexMetadata($document) . "\n";
            $payload .= $this->serializer->getIndexDocument($document) . "\n";
        }
        $result = $this->client->request('POST', "/{$this->indexName}/_bulk", new Message(array('Content-Type' => 'application/json'), $payload));
        if ($result->headers['status'] !== 201 && $result->headers['status'] !== 200) {
            throw new RuntimeException('Wrong HTTP status received from Elasticsearch: ' . $result->headers['status']);
        }
        $this->flush();
    }