updateByQuery #
Updates documents matching the provided search query.
Documents updated that way trigger real-time notifications.
This method also supports the Koncorde Filters DSL to match documents by passing the lang
argument with the value koncorde
.
Koncorde filters will be translated into an Elasticsearch query.
Koncorde bool
operator and regexp
clause are not supported for search queries.
Limitations #
The request fails if the number of documents returned by the search query exceeds the documentsWriteCount
server configuration (see the Configuring Kuzzle guide).
To update a greater number of documents:
- Change the server configuration
- Split the search query
- Use a paginated document:search with document:mUpdate
- Use bulk:updateByQuery
Query Syntax #
HTTP #
URL: http://kuzzle:7512/<index>/<collection>/_query[?refresh=wait_for][&source][&lang=<query language>][&silent]
Method: PUT
Body:
{
"query": {
// query to match documents
},
"changes": {
// documents changes
}
}
Other protocols #
{
"index": "<index>",
"collection": "<collection>",
"controller": "document",
"action": "updateByQuery",
"body": {
"query": {
// query to match documents
},
"changes": {
// documents changes
}
}
}
Kourou #
kourou document:updateByQuery <index> <collection> <body>
kourou document:updateByQuery <index> <collection> <body> -a silent=true
Arguments #
collection
: collection nameindex
: index name
Optional: #
refresh
: if set towait_for
, Kuzzle will not respond until the update is indexedsource
: if set totrue
Kuzzle will return the updated documents body in the response.lang
: specify the query language to use. By default, it'selasticsearch
butkoncorde
can also be used.Available since 2.8.0silent
: if set, then Kuzzle will not generate notificationsAvailable since 2.9.2
Body properties #
query
: the search query itself, using the ElasticSearch Query DSL or the Koncorde Filters DSL syntax.changes
: partial changes to apply to the documents
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 contentstatus
: HTTP error 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
{
"status": 200,
"error": null,
"index": "<index>",
"collection": "<collection>",
"controller": "document",
"action": "updateByQuery",
"requestId": "<unique request identifier>",
"result": {
"successes": [
{
"_id": "document-1",
"_source": "<updated document>", // If `source` option is set to true
"status": 200
},
{
"_id": "document-2",
"_source": "<updated document>", // If `source` option is set to true
"status": 200
}
],
"errors": [
{
"document": {
// updated document content
},
"status": 404,
"reason": "Document 'foobar' not found"
}
]
}
}