SDK
SDK Javascript v7.x
2

deleteByQuery #

Deletes documents matching the provided search query.

Kuzzle uses the ElasticSearch Query DSL syntax.

Available since 7.4.8

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.


Copied to clipboard!
deleteByQuery(index, collection, [query], [options]);
Argument Type Description
index
string
Index name
collection
string
Collection name
query
object
Query to match
options
object
Query options

Options #

Additional query options

Options Type
(default)
Description
lang
string
Specify the query language to use. By default, it's elasticsearch but koncorde can also be used.
Available since 7.4.8
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)
silent
boolean

(false)
If true, then Kuzzle will not generate notifications
Available since 7.5.3
source
boolean
if set to true Kuzzle will return each deleted document body in the response
timeout
number

(-1)
Time (in ms) during which a request will still be waited to be resolved. Set it -1 if you want to wait indefinitely

Resolves #

Resolves to an array of strings containing the deleted document ids.

Usage #

With the ElasticSearch Query DSL syntax.

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

With the Koncorde Filters DSL syntax.

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