SDK
SDK Javascript v7.x
2

updateByQuery #

Updates documents matching the provided search query.

Kuzzle uses the ElasticSearch Query DSL syntax.

Available since 7.4.8

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.

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
lang
string
Specify the query language to use. By default, it's elasticsearch but koncorde can also be used.
Available since 7.4.8
refresh
string

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

(false)
If true, then Kuzzle will not generate notifications
Available since 7.5.3
source
boolean

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

(-1)
Time (in ms) during which a request will still be waited to be resolved. Set it -1 if you want to wait indefinitely

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 #

With the ElasticSearch Query DSL syntax.

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);
}

With the Koncorde Filters DSL syntax.

Copied to clipboard!
try {
  result = await kuzzle.document.updateByQuery(
    'nyc-open-data',
    'yellow-taxi',
    {
      equals: {
        capacity: 4
      }
    },
    {
      capacity: 42
    },
    {
      lang: 'koncorde'
    });
/*
{
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);
}