Update nested documents via painless

Hi,

Assuming we have the following mapping

"mappings": {
  "properties": {
    "id": {
      "type": "text",
    },
    "messages": {
      "type": "nested",
      "dynamic": "strict",
      "properties": {
        "id": {
          "type": "keyword"
        }
      }
    }
  }
}

We are using the _bulk and sending a bunch of UpdateRequest actions with a painless script like the following:

if (ctx._source.messages == null) {ctx._source.messages = new ArrayList();} ctx._source.messages.removeIf(c -> { c.id == params.message.id }); ctx._source.messages.add(params.message);

As you can see, if we have a new update for a given nested message with a specific id, we just remove the old version and add the new version.
I am just wondering if this is the best approach in terms of performance on ES side, or it's worth extending the script to actually go field by field and update to the new value, or even check if the value of the nested message changed and only update it if it actually changed.

What is the overhead on ES side when doing full replacement instead of updating the fields? I know that when a document is updated, a new full version of the doc is created, but does this apply in this specific example?

Thanks.

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