0

我正在尝试通过以下方式更新image.uri字段_update_by_query

POST user/_update_by_query
{
  "script": {
    "source": "ctx._source.image.uri = 'https://example.com/default/image/profile.jpg'",
    "lang": "painless"
  },
  "query": {
    "bool": {
      "must_not": [
         {
              "exists": {
                "field": "image.id"
              }
          }
      ]
    }
  }
}

但它会引发错误:

{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "runtime error",
        "script_stack": [
          "ctx._source.image.uri = 'https://example.com/default/image/profile.jpg'",
          "                 ^---- HERE"
        ],
        "script": "ctx._source.image.uri = 'https://example.com/default/image/profile.jpg'",
        "lang": "painless"
      }
    ],
    "type": "script_exception",
    "reason": "runtime error",
    "script_stack": [
      "ctx._source.image.uri = 'https://example.com/default/image/profile.jpg'",
      "                 ^---- HERE"
    ],
    "script": "ctx._source.image.uri = 'https://example.com/default/image/profile.jpg'",
    "lang": "painless",
    "caused_by": {
      "type": "null_pointer_exception",
      "reason": null
    }
  },
  "status": 500
}

样本文件:

{
    "image": {
        "uri": "https://example.com/resources/uploads/default_files/profile/thumb/large/default_profile.jpg"
    },
    "created": "2018-06-06T21:49:26Z",
    "uid": 1,
    "name": "Jason Cameron",
    "username": "jason"
}
4

1 回答 1

0

更新回复

问题可能来自其中没有image对象的文档。

如果可能,尝试添加strict映射,以避免索引没有image对象的文档。

OLD RESPONSE/"\' 在无痛脚本中作为字符串使用是正确的

您的问题是'用于封装您的 uri,字符串必须由".

尝试将您的脚本修改为:

 "script": {
    "source": "ctx._source.image.uri = \"https://example.com/default/image/profile.jpg\"",
    "lang": "painless"
  }
于 2018-06-21T12:45:42.520 回答