ES:将当前文档保存到子字段作为历史修订

时间:2017-05-22 08:04:21

标签: elasticsearch updates elasticsearch-painless

我正在尝试使用painless脚本实现store older versions within the same document

curl -XPOST http://127.1:9200/index1/type1/docid/_update -d \
{"script": {"inline": "ctx._source.previous.add(ctx._source)"}}

回复是

{
    "error": {
        "root_cause": [{
            "type": "remote_transport_exception",
            "reason": "[DJxHoBx][172.17.0.2:9300][indices:data/write/update[s]]"
        }],
        "type": "illegal_argument_exception",
        "reason": "Object has already been built and is self-referencing itself"
    },
    "status": 400
}

那么我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:0)

通过手动枚举每个键来解决:

ctx._source['previous'].add({'x': ctx._source.x})