deleteByQuery #
Deletes documents matching the provided search query.
Documents removed that way trigger real-time notifications.
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.
Limitations #
The request fails if the number of documents returned by the search query exceeds the documentsWriteCount
server configuration (see the Configuring Kuzzle guide).
This behavior aims at limiting the pressure on memory and on real-time notifications.
To remove a greater number of documents, you can:
- change the server configuration
- split the search query
- use a paginated document:search with document:mDelete
- use bulk:deleteByQuery
To remove all documents from a collection, use collection:truncate instead.
Query Syntax #
HTTP #
URL: http://kuzzle:7512/<index>/<collection>/_query[?refresh=wait_for][&source][&lang=<query language>][&silent]
Method: DELETE
Body:
{
"query": {
// ...
}
}
Other protocols #
{
"index": "<index>",
"collection": "<collection>",
"controller": "document",
"action": "deleteByQuery",
"refresh": "wait_for",
"body": {
"query": {
// ...
}
}
}
Kourou #
kourou document:deleteByQuery <index> <collection> <body>
kourou document:deleteByQuery <index> <collection> <body> -a silent=true
Arguments #
collection
: collection nameindex
: index name
Optional #
refresh
: if set towait_for
, Kuzzle will not respond until the deleted documents are removed from the search indexessource
: if set totrue
Kuzzle will return each deleted document body in the response.lang
: specify the query language to use. By default, it'selasticsearch
butkoncorde
can also be used.Available since 2.8.0silent
: if set, then Kuzzle will not generate notificationsAvailable since 2.9.2
Body properties #
query
: the search query itself, using the ElasticSearch Query DSL or the Koncorde Filters DSL syntax.
Response #
Returns an object containing information about the deleted documents:
ids
: an array containing the list of each deleted document identifierDeprecated since 2.2.1.documents
an array of the deleted documents. These contain their respective contents if thesource
is set totrue
.
{
"status": 200,
"error": null,
"index": "<index>",
"collection": "<collection>",
"controller": "document",
"action": "deleteByQuery",
"requestId": "<unique request identifier>",
"result": {
"documents": [
{
"_id": "<deleted document unique identifier>",
"_source": {
// Document content, Present only if 'source' parameter is set to true.
}
}
],
// Deprecated since 2.2.1, use the documents array instead.
"ids": [
"id 1",
"id 2",
"id ...",
"id n"
]
}
}