0

我以这些数据为例

{
      "_index": "tags",
      "_type": "tag",
      "_id": "AVhDUH51AIyDmaqCQz3I",
      "_score": 1,
      "_source": {
        "tagname": "tag1",
        "tagnameFr": "tag1fr",
        "description": "Some description",
        "descriptionFr": "Some description fr",
        "contests": [
          {
            "id": 22
          },
          {
            "id": 33
          },
          {
            "id": 44
          }
        ],
        "deal": null,
        "category": null
      }
    }

我这样做是为了更新嵌套文档,效果很好

 // $column = 'contests'; $data = ['contest' => array('id' => 1, 'name' => 'test')];
 $this->params['body'] = array(
            'script' => array(
                "inline" => "ctx._source." . $column . ".add(params." . $column . ")",
                "lang" => "painless",
                "params" => $data
            )
        );

但是当我尝试像这样删除时

// $list = 'contests'; and $value = array('id' => 1, 'name' => 'test');
$this->params['body'] = array(
                "script" => "ctx._source." . $list . ".remove(params.item)",
                "lang" => "painless",
                "params" => array(
                    'item' => $value
                )
            );

当我执行上面的代码时,我收到此消息/

Connection.php 第 681 行中的 BadRequest400Exception:{"error":{"root_cause":[{"type":"remote_transport_exception","re​​ason":"[56NCJVE][127.0.0.1:9300][indices:data/write/ update[s]]"}],"type":"illegal_argument_exception","re​​ason":"执行脚本失败","caused_by":{"type":"script_exception","re​​ason":"运行时错误", "caused_by":{"type":"null_pointer_exception","re​​ason":null},"script_stack":["ctx._source.contest.remove(params.item)","^---- HERE"], "script":"ctx._source.contest.remove(params.item)","lang":"painless"}},"status":400}

我也尝试在我的代码中执行此脚本,但我得到与上面相同的错误。

{
  "script": "item_to_remove = nil; foreach (item : ctx._source.list) { if     (item['tweet_id'] == tweet_id) { item_to_remove=item; } } if (item_to_remove != nil) ctx._source.list.remove(item_to_remove);",
    "params": {"tweet_id": "123"}
    }

我正在执行的两个脚本update

$this->client->update($this->params);
4

0 回答 0