How can I add an user to elastic search only if the user doesn't exists as well as user count?
{
"script" : {
"source": "if (ctx._source.users != null){ctx._source.user_count += params.count; ctx._source.users.add(ctx._source.users.indexOf(params.user))}",
"lang": "painless",
"params" : {
"user" : "user123",
"count": 1
}
}
}
In the above code, I'm just adding user without checking whether the user already exists which can result in multiple elements with same username.
Is it possible to add only if user does not exists?