Update documents Added in 2.4.0
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.
Path parameters
-
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
.
Query parameters
-
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 targetingfoo*,bar*
returns an error if an index starts withfoo
but no index starts withbar
. -
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
orproceed
.Values are
abort
orproceed
. -
default_operator string
The default operator for query string query:
AND
orOR
.Values are
and
,AND
,or
, orOR
. -
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 number
Starting offset (default: 0)
-
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 number
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.
-
q string
Query in the Lucene query string syntax.
-
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 number
The throttle for this request in sub-requests per second.
-
routing string
Custom value used to route operations to a specific shard.
-
scroll string
Period to retain the search context for scrolling.
-
scroll_size number
Size of the scroll request that powers the operation.
-
search_timeout string
Explicit timeout for each search request.
-
search_type string
The type of the search operation. Available options:
query_then_fetch
,dfs_query_then_fetch
.Values are
query_then_fetch
ordfs_query_then_fetch
. -
slices number | string
The number of slices this task should be divided into.
-
sort array[string]
A comma-separated list of : pairs.
-
stats array[string]
Specific
tag
of the request for logging and statistical purposes. -
terminate_after number
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 string
Period each update request waits for the following operations: dynamic mapping updates, waiting for active shards.
-
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 number | 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
). -
wait_for_completion boolean
If
true
, the request blocks until the operation is complete.
curl \
-X POST http://api.example.com/{index}/_update_by_query \
-H "Content-Type: application/json" \
-d '{"max_docs":42.0,"query":{},"script":{"source":"string","id":"string","params":{"additionalProperty1":{},"additionalProperty2":{}},"":"painless","options":{"additionalProperty1":"string","additionalProperty2":"string"}},"slice":{"field":"string","id":"string","max":42.0},"conflicts":"abort"}'
{
"max_docs": 42.0,
"query": {},
"script": {
"source": "string",
"id": "string",
"params": {
"additionalProperty1": {},
"additionalProperty2": {}
},
"": "painless",
"options": {
"additionalProperty1": "string",
"additionalProperty2": "string"
}
},
"slice": {
"field": "string",
"id": "string",
"max": 42.0
},
"conflicts": "abort"
}
{
"batches": 42.0,
"failures": [
{
"cause": {
"type": "string",
"reason": "string",
"stack_trace": "string",
"caused_by": {},
"root_cause": [
{}
],
"suppressed": [
{}
]
},
"id": "string",
"index": "string",
"status": 42.0,
"type": "string"
}
],
"noops": 42.0,
"deleted": 42.0,
"requests_per_second": 42.0,
"retries": {
"bulk": 42.0,
"search": 42.0
},
"": 42.0,
"timed_out": true,
"total": 42.0,
"updated": 42.0,
"version_conflicts": 42.0,
"throttled": "string",
"throttled_until": "string"
}