elasticsearch-php upsert 总是提示runtime error?

 mobiledu2502870587 发布于 2022-11-16 01:11

版本

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}
1 个回答
  • 空指针异常,ctx._source.counter脚本不存在

    2022-11-16 01:25 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有