[英]find and update a document in elasticsearch2 using php
我正在嘗試使用 ElasticSearch 查找文檔並更新其中的字段。 代碼是:
require_once 'vendor/autoload.php';
$client = Elasticsearch\ClientBuilder::create()->build();
$params = [
'index' => 'myIndex',
'type' => 'myCollection',
'body' => [
'query'=> [
'match'=> [
'accessToken' => $accessToken
]
] ,
'script' => 'ctx._source.deviceId= deviceId',
'params' => [
'deviceId' => $deviceId
],
'upsert' => [
'counter' => 1
]
]
];
代碼給出500 Internal Error
。 知道我錯過了什么嗎?
如果您想將 deviceid 的值增加 1(意思是如果 deviceid 的值為 4,那么您可以通過向其添加 1 將其增加到 5),然后按照下面的代碼
'script' => 'ctx._source.deviceId= deviceId',
replace with
'script' => 'ctx._source.counter += deviceId',
例子:
$params = [
'index' => 'my_index',
'type' => 'my_type',
'id' => 'my_id',
'body' => [
'script' => 'ctx._source.counter += count',
'params' => [
'count' => 4
],
'upsert' => [
'counter' => 1
]
]
];
$response = $client->update($params);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.