Method: Elasticsearch::API::Actions#delete_by_query

Defined in:
lib/elasticsearch/api/actions/delete_by_query.rb

#delete_by_query(arguments = {}) ⇒ Object

Delete documents which match specified query.

Provide the query either as a “query string” query in the ‘:q` argument, or using the Elasticsearch’s [Query DSL](www.elasticsearch.org/guide/reference/query-dsl/) in the ‘:body` argument.

Examples:

Deleting documents with a simple query


client.delete_by_query index: 'myindex', q: 'title:test'

Deleting documents using the Query DSL


client.delete_by_query index: 'myindex', body: { query: { term: { published: false } } }

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (List)

    A comma-separated list of indices to restrict the operation; use ‘_all`to perform the operation on all indices (Required)

  • :type (List)

    A comma-separated list of types to restrict the operation

  • :body (Hash)

    A query to restrict the operation

  • :analyzer (String)

    The analyzer to use for the query string

  • :consistency (String)

    Specific write consistency setting for the operation (options: one, quorum, all)

  • :default_operator (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

  • :allow_no_indices (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)

  • :expand_wildcards (String)

    Whether to expand wildcard expression to concrete indices that are open, closed or both. (options: open, closed)

  • :ignore_indices (String)

    When performed on multiple indices, allows to ignore ‘missing` ones (options: none, missing) @until 1.0

  • :ignore_unavailable (Boolean)

    Whether specified concrete indices should be ignored when unavailable (missing, closed, etc)

  • :replication (String)

    Specific replication type (options: sync, async)

  • :q (String)

    Query in the Lucene query string syntax

  • :routing (String)

    Specific routing value

  • :source (String)

    The URL-encoded query definition (instead of using the request body)

  • :timeout (Time)

    Explicit operation timeout

Raises:

  • (ArgumentError)

See Also:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/elasticsearch/api/actions/delete_by_query.rb', line 45

def delete_by_query(arguments={})
  Utils.__report_unsupported_method(__method__)

  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]

  valid_params = [
    :analyzer,
    :consistency,
    :default_operator,
    :df,
    :ignore_indices,
    :ignore_unavailable,
    :allow_no_indices,
    :expand_wildcards,
    :replication,
    :q,
    :routing,
    :source,
    :timeout ]

  method = HTTP_DELETE
  path   = Utils.__pathify Utils.__listify(arguments[:index]),
                           Utils.__listify(arguments[:type]),
                           '/_query'

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = arguments[:body]

  perform_request(method, path, params, body).body
end