|
@@ -1,14 +1,20 @@
|
|
|
-[[java-rest-high-document-update]]
|
|
|
+--
|
|
|
+:api: update
|
|
|
+:request: UpdateRequest
|
|
|
+:response: UpdateResponse
|
|
|
+--
|
|
|
+
|
|
|
+[id="{upid}-{api}"]
|
|
|
=== Update API
|
|
|
|
|
|
-[[java-rest-high-document-update-request]]
|
|
|
+[id="{upid}-{api}-request"]
|
|
|
==== Update Request
|
|
|
|
|
|
-An `UpdateRequest` requires the following arguments:
|
|
|
+An +{request}+ requires the following arguments:
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request]
|
|
|
--------------------------------------------------
|
|
|
<1> Index
|
|
|
<2> Type
|
|
@@ -22,7 +28,7 @@ The script can be provided as an inline script:
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request-with-inline-script]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request-with-inline-script]
|
|
|
--------------------------------------------------
|
|
|
<1> Script parameters provided as a `Map` of objects
|
|
|
<2> Create an inline script using the `painless` language and the previous parameters
|
|
@@ -32,7 +38,7 @@ Or as a stored script:
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request-with-stored-script]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request-with-stored-script]
|
|
|
--------------------------------------------------
|
|
|
<1> Reference to a script stored under the name `increment-field` in the `painless` language
|
|
|
<2> Sets the script in the update request
|
|
@@ -45,27 +51,27 @@ The partial document can be provided in different ways:
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request-with-doc-as-string]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request-with-doc-as-string]
|
|
|
--------------------------------------------------
|
|
|
<1> Partial document source provided as a `String` in JSON format
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request-with-doc-as-map]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request-with-doc-as-map]
|
|
|
--------------------------------------------------
|
|
|
<1> Partial document source provided as a `Map` which gets automatically converted
|
|
|
to JSON format
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request-with-doc-as-xcontent]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request-with-doc-as-xcontent]
|
|
|
--------------------------------------------------
|
|
|
<1> Partial document source provided as an `XContentBuilder` object, the Elasticsearch
|
|
|
built-in helpers to generate JSON content
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request-shortcut]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request-shortcut]
|
|
|
--------------------------------------------------
|
|
|
<1> Partial document source provided as `Object` key-pairs, which gets converted to
|
|
|
JSON format
|
|
@@ -76,7 +82,7 @@ will be inserted as a new document using the `upsert` method:
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request-upsert]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request-upsert]
|
|
|
--------------------------------------------------
|
|
|
<1> Upsert document source provided as a `String`
|
|
|
|
|
@@ -89,27 +95,27 @@ The following arguments can optionally be provided:
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request-routing]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request-routing]
|
|
|
--------------------------------------------------
|
|
|
<1> Routing value
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request-timeout]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request-timeout]
|
|
|
--------------------------------------------------
|
|
|
<1> Timeout to wait for primary shard to become available as a `TimeValue`
|
|
|
<2> Timeout to wait for primary shard to become available as a `String`
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request-refresh]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request-refresh]
|
|
|
--------------------------------------------------
|
|
|
<1> Refresh policy as a `WriteRequest.RefreshPolicy` instance
|
|
|
<2> Refresh policy as a `String`
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request-retry]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request-retry]
|
|
|
--------------------------------------------------
|
|
|
<1> How many times to retry the update operation if the document to update has
|
|
|
been changed by another operation between the get and indexing phases of the
|
|
@@ -117,103 +123,68 @@ update operation
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request-no-source]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request-no-source]
|
|
|
--------------------------------------------------
|
|
|
<1> Enable source retrieval, disabled by default
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request-source-include]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request-source-include]
|
|
|
--------------------------------------------------
|
|
|
<1> Configure source inclusion for specific fields
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request-source-exclude]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request-source-exclude]
|
|
|
--------------------------------------------------
|
|
|
<1> Configure source exclusion for specific fields
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request-version]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request-version]
|
|
|
--------------------------------------------------
|
|
|
<1> Version
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request-detect-noop]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request-detect-noop]
|
|
|
--------------------------------------------------
|
|
|
<1> Disable the noop detection
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request-scripted-upsert]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request-scripted-upsert]
|
|
|
--------------------------------------------------
|
|
|
<1> Indicate that the script must run regardless of whether the document exists or not,
|
|
|
ie the script takes care of creating the document if it does not already exist.
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request-doc-upsert]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request-doc-upsert]
|
|
|
--------------------------------------------------
|
|
|
<1> Indicate that the partial document must be used as the upsert document if it
|
|
|
does not exist yet.
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-request-active-shards]
|
|
|
+include-tagged::{doc-tests-file}[{api}-request-active-shards]
|
|
|
--------------------------------------------------
|
|
|
<1> Sets the number of shard copies that must be active before proceeding with
|
|
|
the update operation.
|
|
|
<2> Number of shard copies provided as a `ActiveShardCount`: can be `ActiveShardCount.ALL`,
|
|
|
`ActiveShardCount.ONE` or `ActiveShardCount.DEFAULT` (default)
|
|
|
|
|
|
-[[java-rest-high-document-update-sync]]
|
|
|
-==== Synchronous Execution
|
|
|
-
|
|
|
-["source","java",subs="attributes,callouts,macros"]
|
|
|
---------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-execute]
|
|
|
---------------------------------------------------
|
|
|
-
|
|
|
-[[java-rest-high-document-update-async]]
|
|
|
-==== Asynchronous Execution
|
|
|
-
|
|
|
-The asynchronous execution of an update request requires both the `UpdateRequest`
|
|
|
-instance and an `ActionListener` instance to be passed to the asynchronous
|
|
|
-method:
|
|
|
-
|
|
|
-["source","java",subs="attributes,callouts,macros"]
|
|
|
---------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-execute-async]
|
|
|
---------------------------------------------------
|
|
|
-<1> The `UpdateRequest` to execute and the `ActionListener` to use when
|
|
|
-the execution completes
|
|
|
-
|
|
|
-The asynchronous method does not block and returns immediately. Once it is
|
|
|
-completed the `ActionListener` is called back using the `onResponse` method
|
|
|
-if the execution successfully completed or using the `onFailure` method if
|
|
|
-it failed.
|
|
|
-
|
|
|
-A typical listener for `UpdateResponse` looks like:
|
|
|
-
|
|
|
-["source","java",subs="attributes,callouts,macros"]
|
|
|
---------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-execute-listener]
|
|
|
---------------------------------------------------
|
|
|
-<1> Called when the execution is successfully completed. The response is
|
|
|
-provided as an argument.
|
|
|
-<2> Called in case of failure. The raised exception is provided as an argument.
|
|
|
+include::../execution.asciidoc[]
|
|
|
|
|
|
-[[java-rest-high-document-update-response]]
|
|
|
+[id="{upid}-{api}-response"]
|
|
|
==== Update Response
|
|
|
|
|
|
-The returned `UpdateResponse` allows to retrieve information about the executed
|
|
|
- operation as follows:
|
|
|
+The returned +{response}+ allows to retrieve information about the executed
|
|
|
+operation as follows:
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-response]
|
|
|
+include-tagged::{doc-tests-file}[{api}-response]
|
|
|
--------------------------------------------------
|
|
|
<1> Handle the case where the document was created for the first time (upsert)
|
|
|
<2> Handle the case where the document was updated
|
|
@@ -227,7 +198,7 @@ source of the updated document:
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-getresult]
|
|
|
+include-tagged::{doc-tests-file}[{api}-getresult]
|
|
|
--------------------------------------------------
|
|
|
<1> Retrieve the updated document as a `GetResult`
|
|
|
<2> Retrieve the source of the updated document as a `String`
|
|
@@ -240,7 +211,7 @@ It is also possible to check for shard failures:
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-failure]
|
|
|
+include-tagged::{doc-tests-file}[{api}-failure]
|
|
|
--------------------------------------------------
|
|
|
<1> Handle the situation where number of successful shards is less than
|
|
|
total shards
|
|
@@ -252,7 +223,7 @@ which needs to be handled as follows:
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-docnotfound]
|
|
|
+include-tagged::{doc-tests-file}[{api}-docnotfound]
|
|
|
--------------------------------------------------
|
|
|
<1> Handle the exception thrown because the document not exist
|
|
|
|
|
@@ -261,6 +232,6 @@ be thrown:
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
--------------------------------------------------
|
|
|
-include-tagged::{doc-tests}/CRUDDocumentationIT.java[update-conflict]
|
|
|
+include-tagged::{doc-tests-file}[{api}-conflict]
|
|
|
--------------------------------------------------
|
|
|
<1> The raised exception indicates that a version conflict error was returned.
|