getIndexMetadata() public method

Note: _index parameter is omitted because it is configurable on a gateway and passed as a part of the REST resource in {@link \eZ\Publish\Core\Search\Elasticsearch\Content\Gateway::bulkIndex()}.
See also: eZ\Publish\Core\Search\Elasticsearch\Content\Gateway::bulkIndex()
public getIndexMetadata ( Document $document ) : string
$document Document
return string
Beispiel #1
0
 /**
  * Performs bulk index of a given array of documents.
  *
  * @param \eZ\Publish\Core\Search\Elasticsearch\Content\Document[] $documents
  */
 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();
 }