What's the preferred way to update part of a nested document

My document has a nested structure like this:

PUT /customer/_doc/1
{
  "name": "hello",
  "body": {
    "module": "aa",
    "config": "bb"
  }
}

Now, I'd like to update body field to be:

{
    "module": "cc",
    "args": "dd"
}

Pay attention I need to:

  1. update the value associated to module
  2. remove the config field
  3. add an args field

I tried to use update API

POST /customer/_update/1
{
  "doc": {
    "body":     {
        "module": "cc",
        "args": "dd"
    }
  }
}

It almost works, but the problem is that the config field is not removed

GET /customer/_doc/1

{
 ...
  "_source" : {
    "name" : "hello",
    "body" : {
      "module" : "cc",
      "config" : "bb",
      "args" : "dd"
    }
  }

}

Is the exact merging algorithm used by update API documented somewhere?

Is there a way to achieve this without writing a script?
I don't want to get the document, do the merge and ind it again ( I prefer to use the update API to avoid roundtrips and benefit from auto retry mechanism)

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.