我有点怀疑你在刷屏

es7.8脚本更新字段,字段名中可以带有短横线“-”么?

Elasticsearch | 作者 es_smallwhite | 发布于2020年12月08日 | 阅读数:1738

文档内容如下:
PUT /parts/_doc/1
{
  "test-parts" : [],
  "mint" : 1
}
更新脚本如下:
POST parts/_update/1
{
  "script": {
    "source": "ctx._source.test-parts.add(params.part)",
    "lang": "painless",
    "params": {
      "part": {"1" : "abhuj"}
    }
  }
}
执行报错:
{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "failed to execute script"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "failed to execute script",
    "caused_by" : {
      "type" : "script_exception",
      "reason" : "compile error",
      "script_stack" : [
        "ctx._source.test-parts.add(params.part)",
        "                 ^---- HERE"
      ],
      "script" : "ctx._source.test-parts.add(params.part)",
      "lang" : "painless",
      "position" : {
        "offset" : 17,
        "start" : 0,
        "end" : 39
      },
      "caused_by" : {
        "type" : "illegal_argument_exception",
        "reason" : "Variable [parts] is not defined."
      }
    }
  },
  "status" : 400
}
将文档字段中“-”去掉或修改,可正常完成。
新人求教,希望得到解答。
 
已邀请:

pony_maggie - 公众号:犀牛饲养员的技术笔记

赞同来自:

变量命名不符合painless规范,需要满足下面的语法:
 
ID: [_a-zA-Z] [_a-zA-Z-0-9]*;

你可以考虑使用下划线

要回复问题请先登录注册