我正在尝试向文档中添加一个类似于https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#_scripted_updates的字段。但是,由于字段是连字符分隔(似乎被视为减号)而不是下划线分隔,我似乎遇到了问题。
以下示例正文:
{"script":"ctx._source.path.to.hyphen-separated-field = \"new data\""}
我试图用反斜杠逃避连字符,但没有运气。
答案 0 :(得分:2)
您可以使用方括号访问该字段,即只需这样做:
{"script": "ctx._source.path.to['hyphen-separated-field'] = \"new data\""}
答案 1 :(得分:0)
这个在2.x(或者也许是其他版本)上为我工作:
"script": {
"inline": "ctx._source.path.to[field] = val",
"params": {
"val": "This is the new value",
"field": "hyphen-separated-field"
}
}
答案 2 :(得分:-1)
或者这也可行
{"script": "ctx._source.path.to.'hyphen-separated-field' = 'new data'"}