Javascript 7.x

deleteByQuery

Deletes documents matching the provided search query.

This is a low level route intended to bypass Kuzzle actions on document deletion, notably:


Copied to clipboard!
deleteByQuery(index, collection, [query], [options]);
Argument Type Description
index
string
Index name
collection
string
Collection name
query
object
documents matching this search query will be deleted. Uses the ElasticSearch Query DSL syntax.
options
object
Query options

Options

Additional query options

Options Type
(default)
Description
queuable
boolean

(true)
If true, queues the request during downtime, until connected to Kuzzle again
refresh
string

("")
If set to wait_for, waits for the change to be reflected for search (up to 1s)

Resolves

Resolves to the number of the deleted documents.

Usage

Copied to clipboard!
try {
  const deleted = await kuzzle.bulk.deleteByQuery(
    'nyc-open-data',
    'yellow-taxi',
    {
      query: {
        term: { capacity: 7 }
      }
    }
  );
  console.log(`Successfully deleted ${deleted} documents`);
} catch (error) {
  console.error(error.message);
}