Elasticsearch 脚本 - 意外字符
Elasticsearch Script - Unexpected characters
我正在尝试使用无痛脚本更新文档。我的文档包含类似 "a4ayc/8"
的字段(字段名称包含字符 /
)。
文档示例:
{
"_index" : "user_profile",
"_type" : "_doc",
"_id" : "SQ9/X1iKV7DDJXJLLMAvyt",
"_score" : 1.0,
"_source" : {
"TgdAhWI" : "text",
"a4ayc/8" : 1,
"SyJ3d9Q" : true,
"qBC0wbU" : "2021-05-25T14:22:40.804Z"
}
}
执行以下脚本时,我得到 "a4ayc/8"
字段的异常:
[type=illegal_argument_exception, reason=invalid assignment: cannot
assign a value to division operation [/]]
脚本:
{
"script":{
"source":"ctx._source.TgdAhWI = params.param1; ctx._source.qBC0wbU = params.param2; ctx._source.a4ayc/8 = params.param3; ctx._source.SyJ3d9Q = params.param4; ",
"lang":"painless",
"params":{
"param3":1,
"param4":true,
"param1":"text",
"param2":"2021-05-25T14:22:40.804Z"
}
},
"upsert":{
"TgdAhWI":"text",
"a4ayc/8":1,
"SyJ3d9Q":true,
"qBC0wbU":"2021-05-25T14:22:40.804Z"
}
}
有解决办法吗?
是的,您只需要以不同方式引用该字段,如下所示:
ctx._source['a4ayc/8'] = params.param3
如果您的字段名称以数字开头也是一样的,因为它不是 valid Painless identifier,例如
ctx._source['4a4ayc8'] = params.param3
我正在尝试使用无痛脚本更新文档。我的文档包含类似 "a4ayc/8"
的字段(字段名称包含字符 /
)。
文档示例:
{
"_index" : "user_profile",
"_type" : "_doc",
"_id" : "SQ9/X1iKV7DDJXJLLMAvyt",
"_score" : 1.0,
"_source" : {
"TgdAhWI" : "text",
"a4ayc/8" : 1,
"SyJ3d9Q" : true,
"qBC0wbU" : "2021-05-25T14:22:40.804Z"
}
}
执行以下脚本时,我得到 "a4ayc/8"
字段的异常:
[type=illegal_argument_exception, reason=invalid assignment: cannot assign a value to division operation [/]]
脚本:
{
"script":{
"source":"ctx._source.TgdAhWI = params.param1; ctx._source.qBC0wbU = params.param2; ctx._source.a4ayc/8 = params.param3; ctx._source.SyJ3d9Q = params.param4; ",
"lang":"painless",
"params":{
"param3":1,
"param4":true,
"param1":"text",
"param2":"2021-05-25T14:22:40.804Z"
}
},
"upsert":{
"TgdAhWI":"text",
"a4ayc/8":1,
"SyJ3d9Q":true,
"qBC0wbU":"2021-05-25T14:22:40.804Z"
}
}
有解决办法吗?
是的,您只需要以不同方式引用该字段,如下所示:
ctx._source['a4ayc/8'] = params.param3
如果您的字段名称以数字开头也是一样的,因为它不是 valid Painless identifier,例如
ctx._source['4a4ayc8'] = params.param3