upsert #
Available since 2.8.0
Applies partial changes to a document. If the document doesn't already exist, a new document is created.
Query Syntax #
HTTP #
Available since 2.11.0
URL: http://kuzzle:7512/<index>/<collection>/<_id>/_upsert[?refresh=wait_for][&retryOnConflict=<int>][&source][&silent]
Method: POST
Body:
Deprecated since 2.11.0
URL: http://kuzzle:7512/<index>/<collection>/<_id>/_upsert[?refresh=wait_for][&retryOnConflict=<int>][&source][&silent]
Method: PUT
Body:
{
"changes": {
// document partial changes
},
"default": {
// optional: document fields to add to the "update" part if the document
// is created
}
}
Other protocols #
{
"index": "<index>",
"collection": "<collection>",
"controller": "document",
"action": "upsert",
"_id": "<documentId>",
"body": {
"changes": {
// document partial changes
},
"default": {
// optional: document fields to add to the changes if the document
// is created
}
}
}
Kourou #
kourou document:upsert <index> <collection> <id> <body>
kourou document:upsert <index> <collection> <id> <body> -a silent=true
Arguments #
_id
: unique identifier of the document to updatecollection
: collection nameindex
: index name
Optional #
refresh
: if set towait_for
, Kuzzle will not respond until the document is indexedretryOnConflict
: conflicts may occur if the same document gets updated multiple times within a short timespan, in a database cluster. You can set theretryOnConflict
optional argument (with a retry count), to tell Kuzzle to retry the failing updates the specified amount of times before rejecting the request with an error.source
: if set totrue
Kuzzle will return the entire updated document body in the response.silent
: if set, then Kuzzle will not generate notificationsAvailable since 2.9.2
Body properties #
changes
: partial changes to apply to the documentdefault
: (optional) fields to add to the document if it gets created
Response #
Returns information about the updated document:
_id
: document unique identifier_source
: (only if thesource
option is set) actualized document content_version
: updated document versioncreated
: iftrue
, a new document was created, otherwise the document existed and was updated
{
"status": 200,
"error": null,
"index": "<index>",
"collection": "<collection>",
"controller": "document",
"action": "upsert",
"requestId": "<unique request identifier>",
"result": {
"_id": "<documentId>",
"_source": {
// (optional) actualized document content. This property appears only if
// the "source" option is set to true
},
"_version": 2,
"created": false,
}
}
Edit this page on Github(opens new window)