Method: Elasticsearch::API::Actions#update_by_query

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

#update_by_query(arguments = {}) ⇒ Object

Process every document matching a query, potentially updating it

Examples:

Update all documents in the index, eg. to pick up new mappings


client.update_by_query index: 'articles'

Update a property of documents matching a query in the index


client.update_by_query index: 'article',
                       body: {
                         script: { inline: 'ctx._source.views += 1' },
                         query: { match: { title: 'foo' } }
                       }

Parameters:

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

    a customizable set of options

Options Hash (arguments):

  • :index (List)

    A comma-separated list of index names to search; use ‘_all` or empty string to perform the operation on all indices (Required)

  • :type (List)

    A comma-separated list of document types to search; leave empty to perform the operation on all types

  • :body (Hash)

    The search definition using the Query DSL

  • :analyzer (String)

    The analyzer to use for the query string

  • :analyze_wildcard (Boolean)

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

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

  • :explain (Boolean)

    Specify whether to return detailed information about score computation as part of a hit

  • :fields (List)

    A comma-separated list of fields to return as part of a hit

  • :fielddata_fields (List)

    A comma-separated list of fields to return as the field data representation of a field for each hit

  • :from (Number)

    Starting offset (default: 0)

  • :ignore_unavailable (Boolean)

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

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

  • :conflicts (String)

    What to do when the reindex hits version conflicts? (options: abort, proceed)

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

  • :lowercase_expanded_terms (Boolean)

    Specify whether query terms should be lowercased

  • :pipeline (String)

    Ingest pipeline to set on index requests made by this action. (default: none)

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

    A comma-separated list of specific routing values

  • :scroll (Duration)

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

  • :search_type (String)

    Search operation type (options: query_then_fetch, dfs_query_then_fetch)

  • :search_timeout (Time)

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

  • :size (Number)

    Number of hits to return (default: 10)

  • :sort (List)

    A comma-separated list of <field>:<direction> pairs

  • :_source (List)

    True or false to return the _source field or not, or a list of fields to return

  • :_source_exclude (List)

    A list of fields to exclude from the returned _source field

  • :_source_include (List)

    A list of fields to extract and return from the _source field

  • :terminate_after (Number)

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

  • :stats (List)

    Specific ‘tag’ of the request for logging and statistical purposes

  • :suggest_field (String)

    Specify which field to use for suggestions

  • :suggest_mode (String)

    Specify suggest mode (options: missing, popular, always)

  • :suggest_size (Number)

    How many suggestions to return in response

  • :suggest_text (Text)

    The source text for which the suggestions should be returned

  • :timeout (Time)

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

  • :track_scores (Boolean)

    Whether to calculate and return scores even if they are not used for sorting

  • :version (Boolean)

    Specify whether to return document version as part of a hit

  • :version_type (Boolean)

    Should the document increment the version number (internal) on hit or not (reindex)

  • :request_cache (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?

  • :consistency (String)

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

  • :scroll_size (Integer)

    Size on the scroll request powering the update_by_query

  • :wait_for_completion (Boolean)

    Should the request should block until the reindex is complete.

  • :requests_per_second (Float)

    The throttle for this request in sub-requests per second. 0 means set no throttle.

Raises:

  • (ArgumentError)

See Also:



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/elasticsearch/api/actions/update_by_query.rb', line 67

def update_by_query(arguments={})
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]

  valid_params = [
    :analyzer,
    :analyze_wildcard,
    :default_operator,
    :df,
    :explain,
    :fields,
    :fielddata_fields,
    :from,
    :ignore_unavailable,
    :allow_no_indices,
    :conflicts,
    :expand_wildcards,
    :lenient,
    :lowercase_expanded_terms,
    :pipeline,
    :preference,
    :q,
    :routing,
    :scroll,
    :search_type,
    :search_timeout,
    :size,
    :sort,
    :_source,
    :_source_exclude,
    :_source_include,
    :terminate_after,
    :stats,
    :suggest_field,
    :suggest_mode,
    :suggest_size,
    :suggest_text,
    :timeout,
    :track_scores,
    :version,
    :version_type,
    :request_cache,
    :refresh,
    :consistency,
    :scroll_size,
    :wait_for_completion,
    :requests_per_second ]

  method = HTTP_POST

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

  params = Utils.__validate_and_extract_params arguments, valid_params

  body   = arguments[:body]

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