0

I am trying to implement store older versions within the same document using painless scripting:

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

The response is

{
    "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
}

So how can I make this work?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
est
  • 11,429
  • 14
  • 70
  • 118
  • 1
    I think the URL needs to be `index1/type1/docid/_update` – Val May 22 '17 at 08:29
  • @Val sorry for the typo. I edited. – est May 23 '17 at 03:37
  • 1
    And I think `ctx.source` should be `ctx._source`, right? You also probably need to remove the `ctx._source.previous` field in the older version you add into `previous` – Val May 23 '17 at 03:39
  • @Val That's great insight! Now I need to find a way to subMap() or exclude a field in HashLinkedList for painless scripting..... – est May 23 '17 at 03:43

1 Answers1

0

solved by manually enumerate each keys:

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

est
  • 11,429
  • 14
  • 70
  • 118