SDK
SDK Dart Null Safety v3.x
2

updateByQuery #

Updates documents matching the provided search query.

Kuzzle uses the ElasticSearch Query DSL syntax.

Available since change-me

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.


Future<Map<String, dynamic>> updateByQuery(
    String index,
    String collection,
    {
    required Map<String, dynamic> searchQuery,
    required Map<String, dynamic> changes,
    bool waitForRefresh = false,
    bool source = false,
    String lang?
  })
ArgumentTypeDescription
index
String
Index name
collection
String
Collection name
searchQuery
Map<String, dynamic>
Query to match
changes
Map<String, dynamic>
Partial changes to apply to the documents
waitForRefresh
bool

(false)
If set to true, Kuzzle will wait for the persistence layer to finish indexing
source
bool

(false)
If true, returns the updated document inside the response
lang
String?
Specify the query language to use. By default, it's elasticsearch but koncorde can also be used.
Available since change-me

Returns #

A Map<String, dynamic> which has a successes and errors: Each updated document is an object of the successes array with the following properties:

PropertyTypeDescription
_source
Map<String, dynamic>
Updated document (if source option set to true)
_id
String
ID of the udated document
_version
int
Version of the document in the persistent data storage
status
int
HTTP status code

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

PropertyTypeDescription
document
Map<String, dynamic>
Document that causes the error
status
int
HTTP error status
reason
String
Human readable reason

Usage #

With the ElasticSearch Query DSL syntax.

final result = await kuzzle
  .document
  .updateByQuery('nyc-open-data', 'yellow-taxi', searchQuery: {
    'match': {
      'capacity': 4,
    },
  }, 
  changes: {
    'capacity': 42,
  });

With the Koncorde Filters DSL syntax.

final result = await kuzzle
  .document
  .updateByQuery('nyc-open-data', 'yellow-taxi', searchQuery: {
    'equals': {
      'capacity': 4,
    },
  }, 
  changes: {
    'capacity': 42,
  }, lang: 'koncorde');