SDK
SDK Jvm v1.x
2

updateByQuery #

Updates documents matching the provided search query.

Kuzzle uses the ElasticSearch Query DSL syntax.

Available since 1.1.0

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 clauses are not supported for search queries.

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


:::: tabs ::: tab Java

Copied to clipboard!
  public CompletableFuture<Map<String, ArrayList<Object>>> updateByQuery(
    String index,
    String collection,
    Map<String, Object> searchQuery,
    Map<String, Object> changes) throws NotConnectedException, InternalException

  public CompletableFuture<Map<String, ArrayList<Object>>> updateByQuery(
    String index,
    String collection,
    Map<String, Object> searchQuery,
    Map<String, Object> changes,
    Lang lang) throws NotConnectedException, InternalException

  public CompletableFuture<Map<String, ArrayList<Object>>> updateByQuery(
    String index,
    String collection,
    Map<String, Object> searchQuery,
    Map<String, Object> changes,
    Boolean waitForRefresh) throws NotConnectedException, InternalException
  
  public CompletableFuture<Map<String, ArrayList<Object>>> updateByQuery(
    String index,
    String collection,
    Map<String, Object> searchQuery,
    Map<String, Object> changes,
    Boolean waitForRefresh,
    Integer retryOnConflict) throws NotConnectedException, InternalException

  public CompletableFuture<Map<String, ArrayList<Object>>> updateByQuery(
    String index,
    String collection,
    Map<String, Object> searchQuery,
    Map<String, Object> changes,
    Boolean waitForRefresh,
    Integer retryOnConflict,
    Boolean source) throws NotConnectedException, InternalException

  public CompletableFuture<Map<String, ArrayList<Object>>> updateByQuery(
    String index,
    String collection,
    Map<String, Object> searchQuery,
    Map<String, Object> changes,
    Boolean waitForRefresh,
    Integer retryOnConflict,
    Boolean source,
    Lang lang) throws NotConnectedException, InternalException
Argument Type Description
index
String
Index name
collection
String
Collection name
searchQuery
Map<String, Object>
Query to match
changes
Map<String, Object>
Partial changes to apply to the documents
waitForRefresh
Boolean
If set to true, Kuzzle will wait for the persistence layer to finish indexing
source
Boolean
If true, returns the updated document inside the response
lang
Lang
Specify the query language to use. By default, it's elasticsearch but koncorde can also be used.
Available since 1.1.0

Returns #

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

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

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

Property Type Description
document
Map<String, Object>
Document that causes the error
status
Integer
HTTP error status
reason
String
Human readable reason

Usage #

With the ElasticSearch Query DSL syntax.

Copied to clipboard!
Map<String, Object> searchQuery = new HashMap<>();
Map<String, Object> match = new HashMap<>();
match.put("capacity", 4);
searchQuery.put("match", match);
Map<String, Object> changes = new HashMap<>();
changes.put("capacity", 42);
Map<String, ArrayList<Object>> result = kuzzle
  .getDocumentController()
  .updateByQuery("nyc-open-data", "yellow-taxi", searchQuery, changes)
  .get();
/*
{
  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=[]
}
*/

With the Koncorde Filters DSL syntax.

Copied to clipboard!
Map<String, Object> searchQuery = new HashMap<>();
Map<String, Object> equals = new HashMap<>();
equals.put("capacity", 4);
searchQuery.put("equals", equals);
Map<String, Object> changes = new HashMap<>();
changes.put("capacity", 42);
Map<String, ArrayList<Object>> result = kuzzle
  .getDocumentController()
  .updateByQuery("nyc-open-data", "yellow-taxi", searchQuery, changes, Lang.KONCORDE)
  .get();
/*
{
  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=[]
}
*/

::: ::: tab Kotlin

Copied to clipboard!
fun updateByQuery(
  index: String,
  collection: String,
  searchQuery: Map<String, Any?>,
  changes: Map<String, Any?>,
  waitForRefresh: Boolean? = null,
  retryOnConflict: Int? = null,
  source: Boolean? = null,
  lang: Lang = Lang.ELASTICSEARCH): CompletableFuture<Map<String, ArrayList<Any?>>>
Argument Type Description
index
String
Index name
collection
String
Collection name
searchQuery
Map<String, Any?>
Query to match
changes
Map<String, Any?>
Partial changes to apply to the documents
waitForRefresh
Boolean
If set to true, Kuzzle will wait for the persistence layer to finish indexing
retryOnConflict
Int
(optional)
The number of times the database layer should retry in case of version conflict
source
Boolean
If true, returns the updated document inside the response
lang
Lang
Specify the query language to use. By default, it's elasticsearch but koncorde can also be used.
Available since 1.1.0

Returns #

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

Property Type Description
_source
Map<String, Any?>
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:

Property Type Description
document
Map<String, Any?>
Document that causes the error
status
Int
HTTP error status
reason
String
Human readable reason

Usage #

With the ElasticSearch Query DSL syntax.

Copied to clipboard!
val match: Map<String, Any?> =
  HashMap<String, Any?>().apply {
    put("capacity", 4)
  }
val searchQuery: Map<String, Any?> =
  HashMap<String, Any?>().apply {
    put("match", match)
  }
val changes: Map<String, Any?> =
  HashMap<String, Any?>().apply {
    put("capacity", 42)
  }
val result: Map<String, ArrayList<Any?>> =
  kuzzle
    .documentController
    .updateByQuery("nyc-open-data", "yellow-taxi", searchQuery, changes)
    .get()
/*
{
  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=[]
}
*/

With the Koncorde Filters DSL syntax.

Copied to clipboard!
val equals: Map<String, Any?> =
  HashMap<String, Any?>().apply {
    put("capacity", 4)
  }
val searchQuery: Map<String, Any?> =
  HashMap<String, Any?>().apply {
    put("equals", equals)  
  }
val changes: Map<String, Any?> =
  HashMap<String, Any?>().apply {
    put("capacity", 42)
  }
val result: Map<String, ArrayList<Any?>> =
  kuzzle
  .documentController
  .updateByQuery("nyc-open-data", "yellow-taxi", searchQuery, changes, lang = Lang.KONCORDE)
  .get()
/*
{
  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=[]
}
*/

::: ::::