更新查询(updateByQuery)Elasticsearch-PHP [英] Update by query (updateByQuery) Elasticsearch-PHP
问题描述
我正在使用弹性搜索2.3 以及官方php驱动程序。 updateByQuery 给我麻烦在php中使用对于如何使用它的一点帮助将不胜感激。
I am Using Elasticsearch 2.3 along with the official php driver. The updateByQuery is giving me troubles to use in php. A little help on how to use it will be appreciated.
$client = \Elasticsearch\ClientBuilder::create()->setHosts(['127.0.0.1:9200'])->build();
# Request
$updateRequest = [
'index' => 'gorocket',
'type' => 'logs',
'body' => [
'query' => [
'filtered' => [
'filter' => [
'bool' => [
'must' =>
[
[
'match' => [ 'enabled' => 1 ],
],
]
]
]
]
]
]
]
];
# Update
$results = $client->updateByQuery($updateRequest);
基本上我想更新几个文档字段(名称,价格)匹配某个查询
Basically i want to update a couple of document fields(name,price) that matches a certain query
谢谢。
推荐答案
所以,在CURL API工作的帮助下,我设法提出了一种方法。
So, with the help of how the CURL api works i managed to come up with a way.
首先你需要编辑你的 elasticsearch.yml
以允许脚本。在最后添加以下行。
First you need to edit your elasticsearch.yml
to allow Scripting. Append the following lines at the end.
script.engine.groovy.inline.search: on
script.engine.groovy.inline.aggs: on
script.engine.groovy.inline.update: on
在那里你可以开始使用查询进行批量更新,如下所示。
There after you can start doing batch updates using queries as the example bellow.
$client = \Elasticsearch\ClientBuilder::create()->setHosts(['127.0.0.1:9200'])->build();
# Request
$updateRequest = [
'index' => 'testindex',
'type' => 'logs',
'conflicts' => 'proceed',
'body' => [
'query' => [
'filtered' => [
'filter' => [
'bool' => [
'must' =>
[
[
'match' => [ 'enabled' => 1 ],
],
]
]
]
]
],
'script' => [
'inline' => 'ctx._source.enabled = value',
'params' => [
'value' => 0
]
]
]
]
];
# Update
$results = $client->updateByQuery($updateRequest);
就是这样。现在不容易,记录得如此。
That's it. It is not easily and well documented as of now so.
这篇关于更新查询(updateByQuery)Elasticsearch-PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!