elasticsearch-php upsert 总是提示runtime error?
大家讲道理
大家讲道理 2017-04-11 09:08:06
0
1
957

版本

Elasticsearch version:5.1

Elasticsearch-php version: 5.0

upsert

文档是:

array(6) { ["_index"]=> string(4) "demo" ["_type"]=> string(4) "demo" ["_id"]=> string(1) "1" ["_version"]=> int(5) ["found"]=> bool(true) ["_source"]=> array(4) { ["a"]=> int(3) ["b"]=> string(1) "a" ["c"]=> string(1) "b" ["d"]=> array(2) { [0]=> string(1) "a" [1]=> string(1) "b" } } }

然后我执行下面的代码:

require_once './vendor/autoload.php'; $client = Elasticsearch\ClientBuilder::create(); $client->setHosts(['127.0.0.1']); $client = $client->build(); print_r($client->update([ 'index' => 'demo', 'type' => 'demo', 'id' => 1, 'body' => [ 'script' => 'ctx._source.counter += 4', 'params' => [ 'count' => 4 ], 'upsert' => [ 'counter' => 1 ] ] ]));

提示我:

Fatal error: Uncaught Elasticsearch\Common\Exceptions\BadRequest400Exception: {"error":{"root_cause":[{"type":"remote_transport_exception","reason":"[shcGs0R][127.0.0.1:9300][indices:data/write/update[s]]"}],"type":"illegal_argument_exception","reason":"failed to execute script","caused_by":{"type":"script_exception","reason":"runtime error","caused_by":{"type":"null_pointer_exception","reason":null},"script_stack":["ctx._source.counter += 4"," ^---- HERE"],"script":"ctx._source.counter += 4","lang":"painless"}},"status":400}
print_r($client->update([ 'index' => 'demo', 'type' => 'demo', 'id' => 1, 'body' => [ 'script' => 'ctx._source.a += params.count', 'params' => [ 'count' => 4 ], ] ]));

这个也提示这个错误:

Fatal error: Uncaught Elasticsearch\Common\Exceptions\BadRequest400Exception: {"error":{"root_cause":[{"type":"remote_transport_exception","reason":"[shcGs0R][127.0.0.1:9300][indices:data/write/update[s]]"}],"type":"illegal_argument_exception","reason":"failed to execute script","caused_by":{"type":"script_exception","reason":"runtime error","caused_by":{"type":"null_pointer_exception","reason":null},"script_stack":["ctx._source.a += params.count"," ^---- HERE"],"script":"ctx._source.a += params.count","lang":"painless"}},"status":400}
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all (1)
伊谢尔伦

空指针异常,ctx._source.counter脚本不存在

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!