I have a collection which gets updated frequently.
- We need to perform upsert operation, i.e., if document doesn't exist then create else update.
- Another constraint we require is timestamp of updated_at should be higher.
Please help. The query will be something like this. But I am getting error even after multiple try.
POST /test/_update/1
{
"scripted_upsert": true,
"script": {
"source": """
if ( ctx.op == 'create' ) {
ctx._source.counter = params.count
} else {
ctx._source.counter += params.count
}
""",
"params": {
"updated_at": "2022-01-17T21:54:29.074Z"
}
},
"upsert": {}
}```