In mongodb update, upsert is just a flag, meaning that the document is created if it does not exist and updated if it exists.
In elasticsearch, one can separately specify a doc json, with fields that are updated, and an upsert json, with fields that are added only to new documents. So, the fields specified in the upsert don't affect existing documents.
Example:
curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{
"doc" : {
"name" : "new_name"
},
"upsert" : {
"is_new" : true
}
}
So, if document 1 exists its name gets changed to "new_name"
, but "is_new"
field is not added. If it does not exist, it will have "is_new" = true
.
Is anything like that feasable in mongodb?
Thanks