Core
API v2.x
2

deleteByQuery #

Deletes documents matching the provided search query.

Documents removed that way trigger real-time notifications.

Available since 2.8.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 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:

To remove all documents from a collection, use collection:truncate instead.


Query Syntax #

HTTP #

Copied to clipboard!
URL: http://kuzzle:7512/<index>/<collection>/_query[?refresh=wait_for][&source][&lang=<query language>][&silent]
Method: DELETE
Body:
Copied to clipboard!
{
  "query": {
    // ...
  }
}

Other protocols #

Copied to clipboard!
{
  "index": "<index>",
  "collection": "<collection>",
  "controller": "document",
  "action": "deleteByQuery",
  "refresh": "wait_for",
  "body": {
    "query": {
      // ...
    }
  }
}

Arguments #

  • collection: collection name
  • index: index name

Optional #

  • refresh: if set to wait_for, Kuzzle will not respond until the deleted documents are removed from the search indexes
  • source: if set to true Kuzzle will return each deleted document body in the response.
  • lang: specify the query language to use. By default, it's elasticsearch but koncorde can also be used.
    Available since 2.8.0
  • silent: if set, then Kuzzle will not generate notifications
    Available since 2.9.2

Body properties #


Response #

Returns an object containing information about the deleted documents:

  • ids: an array containing the list of each deleted document identifier
    Deprecated since 2.2.1
    .
  • documents an array of the deleted documents. These contain their respective contents if the source is set to true.
Copied to clipboard!
{
  "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"
    ]
  }
}