mUpsert #
Available since 2.11.0
Applies partial changes to multiple documents. If a document doesn't already exist, a new document is created.
The number of documents that can be updated by a single request is limited by the documentsWriteCount
server configuration (see the Configuring Kuzzle guide).
Query Syntax #
HTTP #
URL: http://kuzzle:7512/<index>/<collection>/_mUpsert[?refresh=wait_for][&retryOnConflict=<retries>][&silent]
Method: POST
Body:
{
"documents": [
{
"_id": "<documentId>",
"changes": {
// document partial changes
},
"default": {
// optional: document fields to add to the "update" part if the document
// is created
}
},
{
"_id": "<anotherDocumentId>",
"changes": {
// document partial changes
},
}
]
}
Other protocols #
{
"index": "<index>",
"collection": "<collection>",
"controller": "document",
"action": "mUpsert",
"body": {
"documents": [
{
"_id": "<documentId>",
"changes": {
// document partial changes
},
"default": {
// optional: document fields to add to the "update" part if the document
// is created
}
},
{
"_id": "<anotherDocumentId>",
"changes": {
// document partial changes
},
}
]
}
}
Kourou #
kourou document:mUpsert <index> <collection> <body>
kourou document:mUpsert <index> <collection> <body> -a silent=true
Arguments #
collection
: collection nameindex
: index name
Optional: #
refresh
: if set towait_for
, Kuzzle will not respond until the updates are 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.silent
: if set, then Kuzzle will not generate notificationsstrict
: if set, an error will occur if a document was not updated
Body properties #
documents
: an array of object. Each object describes a document to update, by exposing the following properties:_id
: ID of the document to replacechanges
: partial changes to apply to the documentdefault
: (optional) fields to add to the document if it gets created
Response #
Returns an object containing 2 arrays: successes
and errors
Each updated document is an object of the successes
array with the following properties:
_id
: document unique identifier_source
: document content_version
: updated document versioncreated
: iftrue
, a new document was created, otherwise the document existed and was updatedstatus
: HTTP status code
Each errored document is an object of the errors
array with the following properties:
document
: original document that caused the errorstatus
: HTTP error status codereason
: human readable reason
If strict
mode is enabled, will rather return an error if at least one document has not been updated.
{
"status": 200,
"error": null,
"index": "<index>",
"collection": "<collection>",
"action": "mUpsert",
"controller": "document",
"requestId": "<unique request identifier>",
"result": {
"successes": [
{
"_id": "<documentId>",
"created": false,
"status": 200,
"_source": {
// updated document content
},
"_version": 2
},
{
"_id": "<anotherDocumentId>",
"created": true,
"status": 200,
"_source": {
// created document content
},
"_version": 2
}
],
"errors": [
{
"document": {
// document content to update
},
"status": 400,
"reason": "document changes must be an object"
}
]
}
}
Edit this page on Github(opens new window)