本文整理汇总了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]);
}
示例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();
}
示例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];
}
}
示例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]]]);
}
示例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);
}
示例6: updateStatement
/**
* Execute a update statement on index;.
*
* @param $params
*
* @return array
*/
public function updateStatement(array $params)
{
return $this->elastic->update($this->setStatementIndex($params));
}
示例7: update
/**
* Update a document index.
*
* @param array $params
*
* @return array
*/
public function update(array $params)
{
return $this->client->update($this->prepareParams($params));
}
示例8: documentUpdate
/**
* Perform an insertion into the engine.
*
* @param array $payload
* @return array
*/
public function documentUpdate($payload)
{
return $this->client->update($payload);
}
示例9: updateDoc
public function updateDoc($type, $id, array $data)
{
return parent::update(['index' => $this->index, 'type' => $type, 'id' => $id, 'body' => ['doc' => $data]]);
}