[英]_update_by_query in elasticserach-php client
I am using elasticsearch 6.2 with elasticsearch-php 6.0 client. 我正在将Elasticsearch 6.2与elasticsearch-php 6.0客户端一起使用。 There is situation i got stuck.
有情况我被卡住了。 I need to update field
userid
= 987 where userid
= 123. I went through update API , Here in every query we need to pass document ID in API
(like POST test/_doc/1/_update
). 我需要更新字段
userid
= 987,其中userid
=123。我通过了update API ,在这里,在每个查询中,我们都需要在API
传递文档ID(例如POST test/_doc/1/_update
)。 First i need to fetch _id
and then i have to make update query with POST test/_doc/{_id}/_update
首先,我需要获取
_id
,然后我必须使用POST test/_doc/{_id}/_update
进行更新查询
It won't possible to every time produce _id
. 不可能每次都产生
_id
。 It didn't help me. 它没有帮助我。
I found another option to use _update_by_query . 我找到了另一个使用_update_by_query的选项。 In which i got success by using following API:
通过使用以下API,我获得了成功:
curl -XPOST 'localhost:9200/my_index/my_type/_update_by_query?pretty' -H 'Content-Type: application/json' -d '
{
"query":{
"term":{
"userid":123
}
},
"script":{
"lang":"painless",
"inline":"ctx._source.userid = params.value",
"params":{
"value":987
}
}
}'
I am not finding any reference which shows how i can use _update_by_query
with elasticserach-php client. 我没有找到任何参考资料,该参考资料说明我如何在
_update_by_query
-php客户端中使用_update_by_query
。 Plus let me know if you guyz have better way to tackle this. 另外,如果您有更好的解决方法,请告诉我。 Thanks!
谢谢!
I got solution So i would like to share: 我有解决方案,所以我想分享:
$client = \Elasticsearch\ClientBuilder::create()->setHosts(['127.0.0.1:9200'])->build();
$update = [
'index' => 'my_index',
'type' => 'my_type',
'conflicts' => 'proceed',
'body' => [
'query' => [
'term' => [
"userid" => 987
]
],
'script' => [
'lang' => 'painless',
'inline' => 'ctx._source.userid = params.userid',
'params' => [
'userid' => 123
]
]
]
];
$results = $client->updateByQuery($update);
It solve my problem. 它解决了我的问题。 I think elasticserach should document this.
我认为elasticserach应该记录下来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.