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.


updateByQuery(index, collection, searchQuery, changes, [options])
ArgumentTypeDescription
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.

OptionsType
(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
queuable
boolean

(true)
If true, queues the request during downtime, until connected to Kuzzle again
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
triggerEvents
boolean

(false)
If set to true, will trigger events even if using Embeded SDK. You should always ensure that your events/pipes does not create an infinite loop.
Available since Kuzzle 2.31.0

Resolves #

Returns an object containing 2 arrays: successes and errors

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

PropertyTypeDescription
_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:

PropertyTypeDescription
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.

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.

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