当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::update方法代码示例

本文整理汇总了PHP中Elasticsearch\Client::update方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::update方法的具体用法?PHP Client::update怎么用?PHP Client::update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Elasticsearch\Client的用法示例。


在下文中一共展示了Client::update方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: update

 /**
  * @param JobInterface $job
  * @return string jobId
  */
 public function update(JobInterface $job)
 {
     $job->validate();
     $params = ['index' => $job->getIndex(), 'type' => $job->getType(), 'id' => $job->getId(), 'body' => ['doc' => $job->getData()]];
     $response = null;
     $i = 0;
     while ($i < 5) {
         try {
             $response = $this->client->update($params);
             break;
         } catch (ServerErrorResponseException $e) {
             // ES server error, try again
             $this->log('error', 'Elastic server error response', ['attemptNo' => $i, 'jobId' => $job->getId(), 'exception' => $e]);
         }
         sleep(1 + intval(pow(2, $i) / 2));
         $i++;
     }
     $i = 0;
     while ($i < 5) {
         $resJob = $this->get($job->getId());
         if ($resJob != null && $resJob->getVersion() >= $response['_version']) {
             return $response['_id'];
         }
         sleep(1 + intval(pow(2, $i) / 2));
         $i++;
     }
     throw new ApplicationException("Unable to find job after update", null, ['job' => $job->getData(), 'elasticResponse' => $response]);
 }
开发者ID:keboola,项目名称:syrup,代码行数:32,代码来源:JobMapper.php

示例2: persist

 /**
  * @param SavableModelInterface $model
  * @throws CouldNotPersistException
  */
 public function persist(SavableModelInterface $model)
 {
     $params = ['index' => $this->index, 'type' => $this->type];
     if ($model->getId()) {
         $params['body'] = ['doc' => $model->toArray()];
         $params['id'] = $model->getId();
         $this->client->update($params);
         $model->markAsStored();
         return;
     }
     $params['body'] = $model->toArray();
     $response = $this->client->index($params);
     $model->id = $response['_id'];
     $model->markAsStored();
 }
开发者ID:systream,项目名称:repository,代码行数:19,代码来源:ElasticSearchStorage.php

示例3: updateUserStatus

 /**
  * @param string $snsid
  * @param int    $status
  *
  * @return array
  */
 protected function updateUserStatus($snsid, $status)
 {
     assert(is_numeric($status));
     $params = ['index' => $this->index, 'type' => $this->type, 'id' => $snsid, 'body' => '{"doc": {"status": "' . $status . '"}}'];
     try {
         $ret = $this->client->update($params);
         return ['snsid' => $snsid, 'version' => $ret['_version']];
     } catch (\Exception $e) {
         $errMsg = $e->getMessage();
         $decodedArray = json_decode($errMsg, true);
         if (is_array($decodedArray)) {
             return ['snsid' => $snsid, 'error' => $decodedArray['status']];
         }
         return ['snsid' => $snsid, 'error' => $errMsg];
     }
 }
开发者ID:jiangyu7408,项目名称:notification,代码行数:22,代码来源:disableUser.php

示例4: saveDocument

 /**
  * {@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]]]);
 }
开发者ID:phroggyy,项目名称:discover,代码行数:35,代码来源:ElasticSearchService.php

示例5: update

 /**
  * @param Searchable $type
  */
 public function update(Searchable $type)
 {
     //clone object so we do not touch original one.
     //this was messing with translatable library.
     //since the parent model saves before the translations,
     //translations wouldn't be in database and we overwrite them here by loading those translations
     $type = clone $type;
     $params = $this->getBaseParams($type);
     $type->load(array_keys($this->config->getWith($type->getSearchableType())));
     $params = array_merge($params, ['id' => $type->getSearchableId(), 'body' => ['doc' => $type->getSearchableDocument()]]);
     if ($type->useSearchableRouting()) {
         $params['routing'] = $type->getSearchableRouting();
     }
     $this->client->update($params);
 }
开发者ID:jaffle-be,项目名称:framework,代码行数:18,代码来源:SearchService.php

示例6: updateStatement

 /**
  * Execute a update statement on index;.
  *
  * @param $params
  *
  * @return array
  */
 public function updateStatement(array $params)
 {
     return $this->elastic->update($this->setStatementIndex($params));
 }
开发者ID:sleimanx2,项目名称:plastic,代码行数:11,代码来源:Connection.php

示例7: update

 /**
  * Update a document index.
  *
  * @param array $params
  *
  * @return array
  */
 public function update(array $params)
 {
     return $this->client->update($this->prepareParams($params));
 }
开发者ID:krisanalfa,项目名称:ductible,代码行数:11,代码来源:Ductible.php

示例8: documentUpdate

 /**
  * Perform an insertion into the engine.
  *
  * @param  array $payload
  * @return array
  */
 public function documentUpdate($payload)
 {
     return $this->client->update($payload);
 }
开发者ID:saulolozano,项目名称:Stretchy,代码行数:10,代码来源:Connection.php

示例9: updateDoc

 public function updateDoc($type, $id, array $data)
 {
     return parent::update(['index' => $this->index, 'type' => $type, 'id' => $id, 'body' => ['doc' => $data]]);
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:4,代码来源:ElasticSearch.php


注:本文中的Elasticsearch\Client::update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。