Method: ElasticsearchServerless::API::Actions#update_by_query

Defined in:
lib/elasticsearch-serverless/api/update_by_query.rb

#update_by_query(arguments = {}) ⇒ Object

Update documents. Updates documents that match the specified query. If no query is specified, performs an update on every document in the data stream or index without modifying the source, which is useful for picking up mapping changes.

Parameters:

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

    a customizable set of options

Options Hash (arguments):

  • :index (String, Array)

    Comma-separated list of data streams, indices, and aliases to search. Supports wildcards (+*+). To search all data streams or indices, omit this parameter or use * or _all. (Required)

  • :allow_no_indices (Boolean)

    If false, the request returns an error if any wildcard expression, index alias, or _all value targets only missing or closed indices. This behavior applies even if the request targets other open indices. For example, a request targeting foo*,bar* returns an error if an index starts with foo but no index starts with bar. Server default: true.

  • :analyzer (String)

    Analyzer to use for the query string.

  • :analyze_wildcard (Boolean)

    If true, wildcard and prefix queries are analyzed.

  • :conflicts (String)

    What to do if update by query hits version conflicts: abort or proceed. Server default: abort.

  • :default_operator (String)

    The default operator for query string query: AND or OR. Server default: OR.

  • :df (String)

    Field to use as default where no field prefix is given in the query string.

  • :expand_wildcards (String, Array<String>)

    Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. Supports comma-separated values, such as open,hidden. Valid values are: all, open, closed, hidden, none.

  • :from (Integer)

    Starting offset (default: 0)

  • :ignore_unavailable (Boolean)

    If false, the request returns an error if it targets a missing or closed index.

  • :lenient (Boolean)

    If true, format-based query failures (such as providing text to a numeric field) in the query string will be ignored.

  • :max_docs (Integer)

    Maximum number of documents to process. Defaults to all documents.

  • :pipeline (String)

    ID of the pipeline to use to preprocess incoming documents. If the index has a default ingest pipeline specified, then setting the value to _none disables the default ingest pipeline for this request. If a final pipeline is configured it will always run, regardless of the value of this parameter.

  • :preference (String)

    Specifies the node or shard the operation should be performed on. Random by default.

  • :refresh (Boolean)

    If true, Elasticsearch refreshes affected shards to make the operation visible to search.

  • :request_cache (Boolean)

    If true, the request cache is used for this request.

  • :requests_per_second (Float)

    The throttle for this request in sub-requests per second. Server default: -1.

  • :routing (String)

    Custom value used to route operations to a specific shard.

  • :scroll (Time)

    Period to retain the search context for scrolling.

  • :scroll_size (Integer)

    Size of the scroll request that powers the operation. Server default: 1000.

  • :search_timeout (Time)

    Explicit timeout for each search request.

  • :search_type (String)

    The type of the search operation. Available options: query_then_fetch, dfs_query_then_fetch.

  • :slices (Integer, String)

    The number of slices this task should be divided into. Server default: 1.

  • :sort (Array<String>)

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

  • :stats (Array<String>)

    Specific tag of the request for logging and statistical purposes.

  • :terminate_after (Integer)

    Maximum number of documents to collect for each shard. If a query reaches this limit, Elasticsearch terminates the query early. Elasticsearch collects documents before sorting. Use with caution. Elasticsearch applies this parameter to each shard handling the request. When possible, let Elasticsearch perform early termination automatically. Avoid specifying this parameter for requests that target data streams with backing indices across multiple data tiers.

  • :timeout (Time)

    Period each update request waits for the following operations: dynamic mapping updates, waiting for active shards. Server default: 1m.

  • :version (Boolean)

    If true, returns the document version as part of a hit.

  • :version_type (Boolean)

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

  • :wait_for_active_shards (Integer, String)

    The number of shard copies that must be active before proceeding with the operation. Set to all or any positive integer up to the total number of shards in the index (+number_of_replicas+1+). Server default: 1.

  • :wait_for_completion (Boolean)

    If true, the request blocks until the operation is complete. Server default: true.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

Raises:

  • (ArgumentError)

See Also:



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
# File 'lib/elasticsearch-serverless/api/update_by_query.rb', line 82

def update_by_query(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "update_by_query" }

  defined_params = [:index].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

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

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

  method = ElasticsearchServerless::API::HTTP_POST
  path   = "#{Utils.listify(_index)}/_update_by_query"
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end