SDK
SDK Javascript v7.x
2

# updateByQuery

Updates documents matching the provided search query.

Kuzzle uses the ElasticSearch Query DSL syntax.

An empty or null query will match all documents in the collection.


Copied to clipboard!
updateByQuery(index, collection, searchQuery, changes, [options])
Argument Type Description
index
string
Index name
collection
string
Collection name
searchQuery
object
Query to match
changes
object
Partial changes to apply to the documents
options
object
Optional parameters

# options

Additional query options.

Options Type
(default)
Description
refresh
string

("")
If set to wait_for, waits for the change to be reflected for search (up to 1s)
source
boolean

(false)
If true, returns the updated document inside the response

# Resolves

Returns an object containing 2 arrays: successes and errors

Each updated document is an object of the successes array with the following properties:

Property Type Description
_source
object<String, Object>
Updated document (if source option set to true)
_id
string
ID of the udated document
_version
number
Version of the document in the persistent data storage
status
number
HTTP status code

Each errored document is an object of the errors array with the following properties:

Property Type Description
document
object<String, Object>
Document that causes the error
status
number
HTTP error status
reason
string
Human readable reason

# Usage

Copied to clipboard!
try {
  result = await kuzzle.document.updateByQuery(
    'nyc-open-data',
    'yellow-taxi',
    {
      match: {
        capacity: 4
      }
    }, {
      capacity: 42
    });
/*
{
successes: [
  {
    _id: <document-id>,
    _source: <updated document> // if source set to true
    status: 200
  },
  {
    _id: <document id>,
    _source: <updated document> // if source set to true
    status: 200
  }
],
errors: []
}
*/
} catch (error) {
  console.log(error.message);
}