Core
API v2.x
2

updateByQuery #

Available since 2.11.0

Updates documents matching the provided search query.

This is a low level route intended to bypass Kuzzle actions on document update, notably:

Under the hood, this action uses Elastic Search scripting feature.


Query Syntax #

HTTP #

Copied to clipboard!
URL: http://kuzzle:7512/<index>/<collection>/_bulk/_query[?refresh=wait_for]
Method: PATCH
Body:
Copied to clipboard!
{
  "query": {
    // query to match documents
  },
  "changes": {
    // documents changes
  }
}

Other protocols #

Copied to clipboard!
{
  "index": "<index>",
  "collection": "<collection>",
  "controller": "document",
  "action": "updateByQuery",
  "refresh": "wait_for",
  "body": {
    "query": {
      // to match documents
    },
    "changes": {
      // documents changes
    }
  }
}

Kourou #

Copied to clipboard!
kourou document:updateByQuery <index> <collection> <body>

Arguments #

  • collection: collection name
  • index: index name

Optional #

  • refresh: if set to wait_for, Kuzzle will not respond until the deleted documents are removed from the search indexes

Body properties #

  • query: documents matching this search query will be updated. Uses the ElasticSearch Query DSL syntax.
  • changes: partial changes to apply to the documents

Even though changes supports deeply nested fields, there are some limitations. Therefore, you will not be able to apply partial changes to an array and will need to replace the whole array.


Response #

Returns the number of updated documents.

Copied to clipboard!
{
  "status": 200,
  "error": null,
  "index": "<index>",
  "collection": "<collection>",
  "controller": "document",
  "action": "updateByQuery",
  "requestId": "<unique request identifier>",
  "result": {
    "updated": 42
}