首页  >  问答  >  正文

elasticsearch-php upsert 总是提示runtime error?

版本

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}
大家讲道理大家讲道理2772 天前1007

全部回复(1)我来回复

  • 伊谢尔伦

    伊谢尔伦2017-04-11 09:10:06

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

    回复
    0
  • 取消回复