public function getTitle(FilePath $path)
 {
     $params = array('index' => $this->index, 'type' => self::MARKDOWN_DOCUMENT_TYPE, 'id' => $path->toAbsoluteUrlString(), '_source_include' => array('title'));
     $result = $this->client->get($params);
     if (null === $result) {
         return null;
     }
     return $result['_source']['title'];
 }
Exemple #2
0
 public function testCreateJob()
 {
     $job = self::$jobFactory->create(uniqid());
     $id = self::$jobMapper->create($job);
     $res = self::$client->get(['index' => self::$index->getIndexNameCurrent(), 'type' => 'jobs', 'id' => $id]);
     $resJob = $res['_source'];
     $job = self::$jobMapper->get($id);
     $this->assertJob($job, $resJob);
     $this->assertEquals($job->getVersion(), $res['_version']);
 }
 /**
  * @param string $identity
  * @return Document
  */
 public function find($identity)
 {
     try {
         $data = $this->client->get(['index' => $this->index, 'type' => $this->type, 'id' => $identity]);
         $documentClass = $this->documentClass;
         return $documentClass::deserialize($data['_source']);
     } catch (Missing404Exception $e) {
     }
     return null;
 }
 /**
  * {@inheritdoc}
  */
 public function saveDocument(Searchable $model)
 {
     $document = $this->constructDocument($model);
     if (!$this->indexIsNested($model->getSearchIndex())) {
         $this->client->index($document);
         return;
     }
     list($index, $type) = $this->retrieveNestedIndex($model->getSearchIndex());
     $class = $this->retrieveParentClass($model->getSearchIndex());
     $parent = $model->belongsTo($class, null, null, class_basename($class))->getResults();
     $parentData = $this->client->get(['id' => $parent->getKey(), 'type' => $parent->getSearchType(), 'index' => $parent->getSearchIndex()])['_source'];
     if (!isset($parentData[$type])) {
         $parentData[$type] = [];
     }
     $children = Collection::make($parentData[$type]);
     if ($child = $children->first(function ($child) use($model) {
         return $child[$model->getKeyName()] == $model->getKey();
     })) {
         $newChildren = $children->map(function ($child) use($model) {
             if ($child[$model->getKeyName()] == $model->getKey()) {
                 $child = $model->documentToArray();
                 if (!isset($document[$model->getKeyName()])) {
                     $child[$model->getKeyName()] = $model->getKey();
                 }
             }
             return $child;
         });
     } else {
         $newChildren = $children->push($model->documentToArray());
     }
     $this->client->update(['id' => $parent->getKey(), 'type' => $parent->getSearchType(), 'index' => $parent->getSearchIndex(), 'body' => ['doc' => [$type => $newChildren]]]);
 }
 /**
  * @param string $identity
  * @return Document
  * @throws DocumentNotFoundException
  */
 public function find(string $identity) : Document
 {
     try {
         $data = $this->client->get($this->createParams($identity));
         return $this->serializer->deserialize($this->serializer->serialize($data['_source']), $this->documentClass);
     } catch (Missing404Exception $e) {
         throw new DocumentNotFoundException($identity);
     }
 }
Exemple #6
0
 /**
  * Execute the request by elasticsearch client
  *
  * @param Client $client
  * @return ResponseInterface
  */
 public function executeByElasticClient(Client $client)
 {
     $params = $this->toElasticClient();
     $responseClass = $this->getResponseClassOfRequest();
     /** @var GetResponseInterface $response */
     $response = new $responseClass();
     $result = RawResponse::build($client->get($params));
     if (null !== $this->document) {
         $response->setDocument($this->document);
     }
     $response->build($result);
     return $response;
 }
 /**
  * Retrieves an entity by its id.
  * @param string $id
  * @return ElasticsearchEntity the entity with the given id or null if none found
  */
 public function findOne($id)
 {
     try {
         $result = $this->elasticsearchClient->get(array('id' => $id, 'index' => $this->index, 'type' => $this->getType()));
         if (!$result || !$result['found']) {
             return null;
         }
         $entity = $this->createEntityFromDocument($result);
         return $entity;
     } catch (Missing404Exception $exc) {
         return null;
     }
 }
 /**
  * @param GetParams $params
  * @return GetResponse
  */
 public function get(GetParams $params)
 {
     return new GetResponse($this->nativeClient->get($params->toArray()));
 }
Exemple #9
0
 /**
  * Get a document index.
  *
  * @param array $params
  *
  * @return array
  */
 public function get(array $params)
 {
     return $this->client->get($this->prepareParams($params));
 }
Exemple #10
0
 /**
  * Perform an insertion into the engine.
  *
  * @param  array $payload
  * @return array
  */
 public function documentGet($payload)
 {
     return $this->client->get($payload);
 }