【发布时间】:2016-04-27 21:07:34
【问题描述】:
curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{ "脚本" : "ctx._source.name_of_new_field = \"value_of_new_field\"" }'
这是来自 elasticsearch 参考站点的一个示例,用于使用新字段更新现有文档。 https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html
我想用“新字段”更新现有文档,但用 json 作为“新字段的值”而不是单个字符串作为“新字段的值”。就像下面一样。
curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{ "脚本" : "ctx._source.test = {\"newTest\":\"hello\"}" }'
返回如下错误。
{
"error": {
"root_cause": [
{
"type": "remote_transport_exception",
"reason": "[Ravage 2099][127.0.0.1:9300][indices:data/write/update[s]]"
}
],
"type": "illegal_argument_exception",
"reason": "failed to execute script",
"caused_by": {
"type": "script_exception",
"reason": "Failed to compile inline script [ctx._source.test2 = {\"test2\":\"hihi\"}] using lang [groovy]",
"caused_by": {
"type": "script_exception",
"reason": "failed to compile groovy script",
"caused_by": {
"type": "multiple_compilation_errors_exception",
"reason": "startup failed:\n4e487d5bc8afde27adf29b77e8427f5da1534843: 1: expecting '}', found ':' @ line 1, column 29.\n ctx._source.test2 = {\"test2\":\"hihi\"}\n ^\n\n1 error\n"
}
}
}
},
"status": 400
}
是否可以用“json value”更新现有文档?还是每个更新请求都应该有单个字符串值?
【问题讨论】:
标签: json elasticsearch