Пример #1
0
 /**
  * Returns a document by identifier
  *
  * @param string $documentClass In short notation (i.e AppBundle:Product)
  * @param string $id
  * @param int    $resultType
  * @return mixed
  */
 public function get($documentClass, $id, $resultType = self::RESULTS_OBJECT)
 {
     $client = $this->getConnection([$documentClass])->getClient();
     $allDocumentClassToIndexMappings = $this->documentMetadataCollector->getDocumentClassesIndices();
     $indexManagerName = $allDocumentClassToIndexMappings[$documentClass];
     $documentMetadata = $this->documentMetadataCollector->getDocumentMetadata($documentClass);
     $params = ['index' => $this->indexManagerRegistry->get($indexManagerName)->getReadAlias(), 'type' => $documentMetadata->getType(), 'id' => $id];
     try {
         $raw = $client->get($params);
     } catch (Missing404Exception $e) {
         return null;
     }
     switch ($resultType & self::BITMASK_RESULT_TYPES) {
         case self::RESULTS_OBJECT:
             return $this->documentConverter->convertToDocument($raw, $documentClass);
         case self::RESULTS_ARRAY:
             return $this->convertToNormalizedArray($raw);
         case self::RESULTS_RAW:
             return $raw;
         default:
             throw new \InvalidArgumentException('Wrong result type selected');
     }
 }
Пример #2
0
 /**
  * Adds document to a bulk request for the next commit.
  * Depending on the connection autocommit mode, the update may be committed right away.
  *
  * @param DocumentInterface $document The document entity to index in ES
  */
 public function persist(DocumentInterface $document)
 {
     $documentArray = $this->documentConverter->convertToArray($document);
     $this->persistRaw(get_class($document), $documentArray);
 }