deleteByQuery

edit
client.deleteByQuery([params, [callback]])

Delete documents from one or more indices and one or more types based on a query.

Check the API Conventions and the elasticsearch docs for more information pertaining to this method.

Deleting documents with a simple query.

await client.deleteByQuery({
  index: 'myindex',
  q: 'test'
});

Deleting documents using the Query DSL.

await client.deleteByQuery({
  index: 'posts',
  body: {
    query: {
      term: { published: false }
    }
  }
});

Params

analyzer

String — The analyzer to use for the query string

analyzeWildcard

Boolean — Specify whether wildcard and prefix queries should be analyzed (default: false)

[defaultOperator=OR]

String — The default operator for query string query (AND or OR)

Options
  • "AND"
  • "OR"

df

String — The field to use as default where no field prefix is given in the query string

from

Number — Starting offset (default: 0)

ignoreUnavailable

Boolean — Whether specified concrete indices should be ignored when unavailable (missing or closed)

allowNoIndices

Boolean — Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes _all string or when no indices have been specified)

[conflicts=abort]

String — What to do when the delete-by-query hits version conflicts?

Options
  • "abort"
  • "proceed"

[expandWildcards=open]

String — Whether to expand wildcard expression to concrete indices that are open, closed or both.

Options
  • "open"
  • "closed"
  • "none"
  • "all"

lenient

Boolean — Specify whether format-based query failures (such as providing text to a numeric field) should be ignored

preference

String — Specify the node or shard the operation should be performed on (default: random)

q

String — Query in the Lucene query string syntax

routing

String, String[], Boolean — A comma-separated list of specific routing values

scroll

DurationString — Specify how long a consistent view of the index should be maintained for scrolled search

searchType

String — Search operation type

Options
  • "query_then_fetch"
  • "dfs_query_then_fetch"

searchTimeout

DurationString — Explicit timeout for each search request. Defaults to no timeout.

size

Number — Number of hits to return (default: 10)

sort

String, String[], Boolean — A comma-separated list of <field>:<direction> pairs

_source

String, String[], Boolean — True or false to return the _source field or not, or a list of fields to return

_sourceExclude

String, String[], Boolean — A list of fields to exclude from the returned _source field

_sourceInclude

String, String[], Boolean — A list of fields to extract and return from the _source field

terminateAfter

Number — The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early.

stats

String, String[], Boolean — Specific tag of the request for logging and statistical purposes

version

Boolean — Specify whether to return document version as part of a hit

requestCache

Boolean — Specify if request cache should be used for this request or not, defaults to index level setting

refresh

Boolean — Should the effected indexes be refreshed?

[timeout=1m]

DurationString — Time each individual bulk request should wait for shards that are unavailable.

waitForActiveShards

String — Sets the number of shard copies that must be active before proceeding with the delete by query operation. Defaults to 1, meaning the primary shard only. Set to all for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)

scrollSize

Number — Size on the scroll request powering the update_by_query

[waitForCompletion=true]

Boolean — Should the request should block until the delete-by-query is complete.

requestsPerSecond

Number — The throttle for this request in sub-requests per second. -1 means no throttle.

[slices=1]

Number — The number of slices this task should be divided into. Defaults to 1 meaning the task isn’t sliced into subtasks.

index

String, String[], Boolean — A comma-separated list of index names to search; use _all or empty string to perform the operation on all indices

type

String, String[], Boolean — A comma-separated list of document types to search; leave empty to perform the operation on all types

body

Object, JSON — The request body, as either JSON or a JSON serializable object. See the elasticsearch docs for details about what can be specified here.

back to top