Class UpdateRequest<TDocument,TPartialDocument>
- All Implemented Interfaces:
JsonpSerializable
Update a document by running a script or passing a partial document.
If the Elasticsearch security features are enabled, you must have the
index or write index privilege for the target index
or index alias.
The script can update, delete, or skip modifying the document. The API also supports passing a partial document, which is merged into the existing document. To fully replace an existing document, use the index API. This operation:
- Gets the document (collocated with the shard) from the index.
- Runs the specified script.
- Indexes the result.
The document must still be reindexed, but using this API removes some network roundtrips and reduces chances of version conflicts between the GET and the index operation.
The _source field must be enabled to use this API. In addition
to _source, you can access the following variables through the
ctx map: _index, _type,
_id, _version, _routing, and
_now (the current timestamp).
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class co.elastic.clients.elasticsearch._types.RequestBase
RequestBase.AbstractBuilder<BuilderT extends RequestBase.AbstractBuilder<BuilderT>> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final JsonpDeserializer<UpdateRequest<Object,Object>> Json deserializer forUpdateRequestbased on named deserializers provided by the callingJsonMapper.static final SimpleEndpoint<UpdateRequest<?,?>, ?> Endpoint "update". -
Method Summary
Modifier and TypeMethodDescriptionstatic <TDocument>
Endpoint<UpdateRequest<?,?>, UpdateResponse<TDocument>, ErrorResponse> createUpdateEndpoint(JsonpDeserializer<TDocument> tDocumentDeserializer) Create an "update" endpoint.static <TDocument,TPartialDocument>
JsonpDeserializer<UpdateRequest<TDocument,TPartialDocument>> createUpdateRequestDeserializer(JsonpDeserializer<TDocument> tDocumentDeserializer, JsonpDeserializer<TPartialDocument> tPartialDocumentDeserializer) Create a JSON deserializer for UpdateRequestfinal BooleanIftrue, theresultin the response is set tonoop(no operation) when there are no changes to the document.final TPartialDocumentdoc()A partial update to an existing document.final BooleanIftrue, use the contents of 'doc' as the value of 'upsert'.final Stringid()Required - A unique identifier for the document to be updated.final LongOnly perform the operation if the document has this primary term.final LongifSeqNo()Only perform the operation if the document has this sequence number.final BooleanTrue or false if to include the document source in the error message in case of parsing errors.final Stringindex()Required - The name of the target index.final Stringlang()The script language.static <TDocument,TPartialDocument>
UpdateRequest<TDocument,TPartialDocument> of(Function<UpdateRequest.Builder<TDocument, TPartialDocument>, ObjectBuilder<UpdateRequest<TDocument, TPartialDocument>>> fn) final Refreshrefresh()If 'true', Elasticsearch refreshes the affected shards to make this operation visible to search.final BooleanIftrue, the destination must be an index alias.final IntegerThe number of times the operation should be retried when a conflict occurs.final Stringrouting()A custom value used to route operations to a specific shard.final Scriptscript()The script to run to update the document.final BooleanIftrue, run the script whether or not the document exists.voidserialize(jakarta.json.stream.JsonGenerator generator, JsonpMapper mapper) Serialize this object to JSON.protected voidserializeInternal(jakarta.json.stream.JsonGenerator generator, JsonpMapper mapper) protected static <TDocument,TPartialDocument>
voidsetupUpdateRequestDeserializer(ObjectDeserializer<UpdateRequest.Builder<TDocument, TPartialDocument>> op, JsonpDeserializer<TDocument> tDocumentDeserializer, JsonpDeserializer<TPartialDocument> tPartialDocumentDeserializer) final SourceConfigsource()Iffalse, turn off source retrieval.final Timetimeout()The period to wait for the following operations: dynamic mapping updates and waiting for active shards.final TDocumentupsert()If the document does not already exist, the contents of 'upsert' are inserted as a new document.final WaitForActiveShardsThe number of copies of each shard that must be active before proceeding with the operation.Methods inherited from class co.elastic.clients.elasticsearch._types.RequestBase
toString
-
Field Details
-
_DESERIALIZER
Json deserializer forUpdateRequestbased on named deserializers provided by the callingJsonMapper. -
_ENDPOINT
Endpoint "update".
-
-
Method Details
-
of
public static <TDocument,TPartialDocument> UpdateRequest<TDocument,TPartialDocument> of(Function<UpdateRequest.Builder<TDocument, TPartialDocument>, ObjectBuilder<UpdateRequest<TDocument, TPartialDocument>>> fn) -
source
Iffalse, turn off source retrieval. You can also specify a comma-separated list of the fields you want to retrieve.API name:
_source -
detectNoop
Iftrue, theresultin the response is set tonoop(no operation) when there are no changes to the document.API name:
detect_noop -
doc
A partial update to an existing document. If bothdocandscriptare specified,docis ignored.API name:
doc -
docAsUpsert
Iftrue, use the contents of 'doc' as the value of 'upsert'. NOTE: Using ingest pipelines withdoc_as_upsertis not supported.API name:
doc_as_upsert -
id
Required - A unique identifier for the document to be updated.API name:
id -
ifPrimaryTerm
Only perform the operation if the document has this primary term.API name:
if_primary_term -
ifSeqNo
Only perform the operation if the document has this sequence number.API name:
if_seq_no -
includeSourceOnError
True or false if to include the document source in the error message in case of parsing errors.API name:
include_source_on_error -
index
Required - The name of the target index. By default, the index is created automatically if it doesn't exist.API name:
index -
lang
The script language.API name:
lang -
refresh
If 'true', Elasticsearch refreshes the affected shards to make this operation visible to search. If 'wait_for', it waits for a refresh to make this operation visible to search. If 'false', it does nothing with refreshes.API name:
refresh -
requireAlias
Iftrue, the destination must be an index alias.API name:
require_alias -
retryOnConflict
The number of times the operation should be retried when a conflict occurs.API name:
retry_on_conflict -
routing
A custom value used to route operations to a specific shard.API name:
routing -
script
The script to run to update the document.API name:
script -
scriptedUpsert
Iftrue, run the script whether or not the document exists.API name:
scripted_upsert -
timeout
The period to wait for the following operations: dynamic mapping updates and waiting for active shards. Elasticsearch waits for at least the timeout period before failing. The actual wait time could be longer, particularly when multiple waits occur.API name:
timeout -
upsert
If the document does not already exist, the contents of 'upsert' are inserted as a new document. If the document exists, the 'script' is run.API name:
upsert -
waitForActiveShards
The number of copies of each shard 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). The default value of1means it waits for each primary shard to be active.API name:
wait_for_active_shards -
serialize
Serialize this object to JSON.- Specified by:
serializein interfaceJsonpSerializable
-
serializeInternal
-
createUpdateRequestDeserializer
public static <TDocument,TPartialDocument> JsonpDeserializer<UpdateRequest<TDocument,TPartialDocument>> createUpdateRequestDeserializer(JsonpDeserializer<TDocument> tDocumentDeserializer, JsonpDeserializer<TPartialDocument> tPartialDocumentDeserializer) Create a JSON deserializer for UpdateRequest -
setupUpdateRequestDeserializer
protected static <TDocument,TPartialDocument> void setupUpdateRequestDeserializer(ObjectDeserializer<UpdateRequest.Builder<TDocument, TPartialDocument>> op, JsonpDeserializer<TDocument> tDocumentDeserializer, JsonpDeserializer<TPartialDocument> tPartialDocumentDeserializer) -
createUpdateEndpoint
public static <TDocument> Endpoint<UpdateRequest<?,?>, createUpdateEndpointUpdateResponse<TDocument>, ErrorResponse> (JsonpDeserializer<TDocument> tDocumentDeserializer) Create an "update" endpoint.
-