This is a followup question to (Is there a way to have field level audit in elastic search?)
Step 1:
#push a sample doc
PUT my_index/_doc/1
{
"created_at": "2025-02-24T13:00:00Z",
"email": "[email protected]",
"name": "dogan",
"field_update_timestamps": {
"email": "2025-02-24T13:00:00Z",
"name": "2025-02-24T13:00:00Z"
}
}
Step 2:
#update the doc with `_update` API call
POST my_index/_update/1
{
"script": {
"source": """
if (!ctx._source.containsKey('field_update_timestamps')) {ctx._source.field_update_timestamps = [:]; }
for (entry in params.entrySet()) {
ctx._source[entry.key] = entry.value; ctx._source.field_update_timestamps[entry.key] =
new java.text.SimpleDateFormat('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'').format(new java.util.Date());
}
""",
"lang": "painless",
"params": {
"name": "musab"
}
}
}
So can we update the same record in the index concurrently? I mean if we start adding different domain like attendance in office or worked from home. {"wfh": "", "wfo": "" concurrently. Please note no 2 separate threads will put the same fields concurrently ie there will be no another thread which will be updating "wfh" or "wfo", however there can be another thread writing "email". Will there be any optimistic lock exception or data loss?
Thanks
Cc: @Musab Dugan
