Thanks @jetnet for providing an idea to loop through all the entries in the map. When I used the script, it was still replacing the entire object, so had to adapt it as per the below to preserve the fields not supplied during an update operation. For context, if I first insert a document that has three objects each with 2 fields, if I then updated that document with the same 3 objects, but with 1 field each, the output is that I end up with a document with 3 objects each with 1 field instead of 3 objects with 2 fields each as I had originally.
I had to adapt @jetnet's script to give me the desired outcome of not overwriting object properties
POST /transaction_index/_update/33384637-3137-3132-5543-31304c4c3151
{
"script": {
"source": "if (ctx._source.Metadata == null || params.Metadata.Version >= ctx._source.Metadata.Version) { for (k in params.keySet()){ if (ctx._source[k] != null) { ctx._source[k].putAll(params.get(k)) } else { ctx._source.put(k, params.get(k)) } } } else { ctx.op = 'none' }",
"params": {
"Transaction": {
"TransactionId": "33384637-3137-3132-5543-31304c4c3151",
"TransactionKey": "Key1"
},
"Message": {
"MessageId": "505a5953-374a-385a-4a48-52353549445a",
"Context": "This is a test context"
},
"MessageDefinition": {
"MessageDefinitionId": "a1c05e06-fa6b-40ce-992f-d083ff6c0243",
"Code": 1010101010
},
"Metadata": {
"Version": 1,
"CreateTime": "2020-09-04T14:27:51.1986439+01:00",
"IsLatest": true,
"IsDummy": false,
"VersionString": "20200903111111"
}
}
},
"scripted_upsert": true,
"upsert": {}
}