2018-10-29 10:32:17 -04:00
|
|
|
|
--
|
|
|
|
|
:api: update-by-query
|
|
|
|
|
:request: UpdateByQueryRequest
|
|
|
|
|
:response: UpdateByQueryResponse
|
|
|
|
|
--
|
|
|
|
|
|
|
|
|
|
[id="{upid}-{api}"]
|
2018-09-02 15:15:00 -04:00
|
|
|
|
=== Update By Query API
|
|
|
|
|
|
2018-10-29 10:32:17 -04:00
|
|
|
|
[id="{upid}-{api}-request"]
|
2018-09-02 15:15:00 -04:00
|
|
|
|
==== Update By Query Request
|
|
|
|
|
|
2018-10-29 10:32:17 -04:00
|
|
|
|
A +{request}+ can be used to update documents in an index.
|
2018-09-02 15:15:00 -04:00
|
|
|
|
|
2018-10-29 10:32:17 -04:00
|
|
|
|
It requires an existing index (or a set of indices) on which the update is to
|
|
|
|
|
be performed.
|
2018-09-02 15:15:00 -04:00
|
|
|
|
|
2018-10-29 10:32:17 -04:00
|
|
|
|
The simplest form of a +{request}+ looks like this:
|
2018-09-02 15:15:00 -04:00
|
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
|
include-tagged::{doc-tests-file}[{api}-request]
|
2018-09-02 15:15:00 -04:00
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
|
<1> Creates the +{request}+ on a set of indices.
|
2018-09-02 15:15:00 -04:00
|
|
|
|
|
2018-10-29 10:32:17 -04:00
|
|
|
|
By default version conflicts abort the +{request}+ process but you can just
|
|
|
|
|
count them instead with:
|
2018-09-02 15:15:00 -04:00
|
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
|
include-tagged::{doc-tests-file}[{api}-request-conflicts]
|
2018-09-02 15:15:00 -04:00
|
|
|
|
--------------------------------------------------
|
|
|
|
|
<1> Set `proceed` on version conflict
|
|
|
|
|
|
2018-10-16 10:46:14 -04:00
|
|
|
|
You can limit the documents by adding a query.
|
2018-09-02 15:15:00 -04:00
|
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
|
include-tagged::{doc-tests-file}[{api}-request-query]
|
2018-09-02 15:15:00 -04:00
|
|
|
|
--------------------------------------------------
|
2018-10-16 10:46:14 -04:00
|
|
|
|
<1> Only copy documents which have field `user` set to `kimchy`
|
2018-09-02 15:15:00 -04:00
|
|
|
|
|
|
|
|
|
It’s also possible to limit the number of processed documents by setting size.
|
|
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
|
include-tagged::{doc-tests-file}[{api}-request-size]
|
2018-09-02 15:15:00 -04:00
|
|
|
|
--------------------------------------------------
|
|
|
|
|
<1> Only copy 10 documents
|
|
|
|
|
|
2018-10-29 10:32:17 -04:00
|
|
|
|
By default +{request}+ uses batches of 1000. You can change the batch size with
|
|
|
|
|
`setBatchSize`.
|
2018-09-02 15:15:00 -04:00
|
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
|
include-tagged::{doc-tests-file}[{api}-request-scrollSize]
|
2018-09-02 15:15:00 -04:00
|
|
|
|
--------------------------------------------------
|
|
|
|
|
<1> Use batches of 100 documents
|
|
|
|
|
|
|
|
|
|
Update by query can also use the ingest feature by specifying a `pipeline`.
|
|
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
|
include-tagged::{doc-tests-file}[{api}-request-pipeline]
|
2018-09-02 15:15:00 -04:00
|
|
|
|
--------------------------------------------------
|
|
|
|
|
<1> set pipeline to `my_pipeline`
|
|
|
|
|
|
2018-10-29 10:32:17 -04:00
|
|
|
|
+{request}+ also supports a `script` that modifies the document:
|
2018-09-02 15:15:00 -04:00
|
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
|
include-tagged::{doc-tests-file}[{api}-request-script]
|
2018-09-02 15:15:00 -04:00
|
|
|
|
--------------------------------------------------
|
|
|
|
|
<1> `setScript` to increment the `likes` field on all documents with user `kimchy`.
|
|
|
|
|
|
2018-10-29 10:32:17 -04:00
|
|
|
|
+{request}+ can be parallelized using `sliced-scroll` with `setSlices`:
|
2018-09-02 15:15:00 -04:00
|
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
|
include-tagged::{doc-tests-file}[{api}-request-slices]
|
2018-09-02 15:15:00 -04:00
|
|
|
|
--------------------------------------------------
|
|
|
|
|
<1> set number of slices to use
|
|
|
|
|
|
|
|
|
|
`UpdateByQueryRequest` uses the `scroll` parameter to control how long it keeps the "search context" alive.
|
|
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
|
include-tagged::{doc-tests-file}[{api}-request-scroll]
|
2018-09-02 15:15:00 -04:00
|
|
|
|
--------------------------------------------------
|
|
|
|
|
<1> set scroll time
|
|
|
|
|
|
|
|
|
|
If you provide routing then the routing is copied to the scroll query, limiting the process to the shards that match
|
|
|
|
|
that routing value.
|
|
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
|
include-tagged::{doc-tests-file}[{api}-request-routing]
|
2018-09-02 15:15:00 -04:00
|
|
|
|
--------------------------------------------------
|
|
|
|
|
<1> set routing
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
==== Optional arguments
|
|
|
|
|
In addition to the options above the following arguments can optionally be also provided:
|
|
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
|
include-tagged::{doc-tests-file}[{api}-request-timeout]
|
2018-09-02 15:15:00 -04:00
|
|
|
|
--------------------------------------------------
|
|
|
|
|
<1> Timeout to wait for the update by query request to be performed as a `TimeValue`
|
|
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
|
include-tagged::{doc-tests-file}[{api}-request-refresh]
|
2018-09-02 15:15:00 -04:00
|
|
|
|
--------------------------------------------------
|
|
|
|
|
<1> Refresh index after calling update by query
|
|
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
|
include-tagged::{doc-tests-file}[{api}-request-indicesOptions]
|
2018-09-02 15:15:00 -04:00
|
|
|
|
--------------------------------------------------
|
|
|
|
|
<1> Set indices options
|
|
|
|
|
|
2018-10-29 10:32:17 -04:00
|
|
|
|
include::../execution.asciidoc[]
|
2018-09-02 15:15:00 -04:00
|
|
|
|
|
2018-10-29 10:32:17 -04:00
|
|
|
|
[id="{upid}-{api}-response"]
|
2018-09-02 15:15:00 -04:00
|
|
|
|
==== Update By Query Response
|
|
|
|
|
|
2019-01-07 08:44:12 -05:00
|
|
|
|
The returned +{response}+ contains information about the executed operations and
|
2018-10-29 10:32:17 -04:00
|
|
|
|
allows to iterate over each result as follows:
|
2018-09-02 15:15:00 -04:00
|
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
|
include-tagged::{doc-tests-file}[{api}-response]
|
2018-09-02 15:15:00 -04:00
|
|
|
|
--------------------------------------------------
|
|
|
|
|
<1> Get total time taken
|
|
|
|
|
<2> Check if the request timed out
|
|
|
|
|
<3> Get total number of docs processed
|
|
|
|
|
<4> Number of docs that were updated
|
|
|
|
|
<5> Number of docs that were deleted
|
|
|
|
|
<6> Number of batches that were executed
|
|
|
|
|
<7> Number of skipped docs
|
|
|
|
|
<8> Number of version conflicts
|
|
|
|
|
<9> Number of times request had to retry bulk index operations
|
|
|
|
|
<10> Number of times request had to retry search operations
|
|
|
|
|
<11> The total time this request has throttled itself not including the current throttle time if it is currently sleeping
|
|
|
|
|
<12> Remaining delay of any current throttle sleep or 0 if not sleeping
|
|
|
|
|
<13> Failures during search phase
|
|
|
|
|
<14> Failures during bulk index operation
|