Let's imagine this situation Alice and Bob are connected to the same kuzzle server. There is a document structured like this:
{
"nom": "Festival de l'automne",
"participants": [id1, id2, ...]
}
Alice and bob want to update the document nearly at the same time.
If using kuzzle.document.update()
i have to use a previously stored value on Alice's or Bob's client to update the participants array. That can lead to conflict or data loss.
My question is is there a way to update the "participants" array using the previous values server side ? or is there a way to directly use an elasticsearch query in order to user scripts like
{
"script" : "ctx._source.participants += participants",
"params" : {
"participants" : "idx"
}
}
Kuzzle does not expose Elasticsearch scripting features for security reasons (privilege escalation and heavy scripts that could DOS the server).
You should expose a specific API action to atomically appends new values to an array. This API action should use the Integrated Elasticsearch Client to use a painless script.
You can find more information about how to deal with array in the documentation