code | type | title |
---|---|---|
true |
page |
upsert | API | Core |
Applies partial changes to a document. If the document doesn't already exist, a new document is created.
```http URL: http://kuzzle:7512///<_id>/_upsert[?refresh=wait_for][&retryOnConflict=][&source][&silent] Method: POST Body: ``` ```http URL: http://kuzzle:7512///<_id>/_upsert[?refresh=wait_for][&retryOnConflict=][&source][&silent] Method: PUT Body: ```
{
"changes": {
// document partial changes
},
"default": {
// optional: document fields to add to the "update" part if the document
// is created
}
}
{
"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 document:upsert <index> <collection> <id> <body>
kourou document:upsert <index> <collection> <id> <body> -a silent=true
_id
: unique identifier of the document to updatecollection
: collection nameindex
: index name
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 notifications
changes
: partial changes to apply to the documentdefault
: (optional) fields to add to the document if it gets created
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,
}
}