Class UpdateRequest<TDocument,TPartialDocument>

java.lang.Object
co.elastic.clients.elasticsearch._types.RequestBase
co.elastic.clients.elasticsearch.core.UpdateRequest<TDocument,TPartialDocument>
All Implemented Interfaces:
JsonpSerializable

@JsonpDeserializable public class UpdateRequest<TDocument,TPartialDocument> extends RequestBase implements JsonpSerializable
Update a document.

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:
  • Field Details

  • Method Details

    • of

      public static <TDocument, TPartialDocument> UpdateRequest<TDocument,TPartialDocument> of(Function<UpdateRequest.Builder<TDocument,TPartialDocument>,ObjectBuilder<UpdateRequest<TDocument,TPartialDocument>>> fn)
    • source

      @Nullable public final SourceConfig source()
      If false, turn off source retrieval. You can also specify a comma-separated list of the fields you want to retrieve.

      API name: _source

    • detectNoop

      @Nullable public final Boolean detectNoop()
      If true, the result in the response is set to noop (no operation) when there are no changes to the document.

      API name: detect_noop

    • doc

      @Nullable public final TPartialDocument doc()
      A partial update to an existing document. If both doc and script are specified, doc is ignored.

      API name: doc

    • docAsUpsert

      @Nullable public final Boolean docAsUpsert()
      If true, use the contents of 'doc' as the value of 'upsert'. NOTE: Using ingest pipelines with doc_as_upsert is not supported.

      API name: doc_as_upsert

    • id

      public final String id()
      Required - A unique identifier for the document to be updated.

      API name: id

    • ifPrimaryTerm

      @Nullable public final Long ifPrimaryTerm()
      Only perform the operation if the document has this primary term.

      API name: if_primary_term

    • ifSeqNo

      @Nullable public final Long ifSeqNo()
      Only perform the operation if the document has this sequence number.

      API name: if_seq_no

    • includeSourceOnError

      @Nullable public final Boolean 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

      public final String index()
      Required - The name of the target index. By default, the index is created automatically if it doesn't exist.

      API name: index

    • lang

      @Nullable public final String lang()
      The script language.

      API name: lang

    • refresh

      @Nullable public final Refresh 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

      @Nullable public final Boolean requireAlias()
      If true, the destination must be an index alias.

      API name: require_alias

    • retryOnConflict

      @Nullable public final Integer retryOnConflict()
      The number of times the operation should be retried when a conflict occurs.

      API name: retry_on_conflict

    • routing

      @Nullable public final String routing()
      A custom value used to route operations to a specific shard.

      API name: routing

    • script

      @Nullable public final Script script()
      The script to run to update the document.

      API name: script

    • scriptedUpsert

      @Nullable public final Boolean scriptedUpsert()
      If true, run the script whether or not the document exists.

      API name: scripted_upsert

    • timeout

      @Nullable public final Time 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

      @Nullable public final TDocument 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

      @Nullable public final WaitForActiveShards 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 of 1 means it waits for each primary shard to be active.

      API name: wait_for_active_shards

    • serialize

      public void serialize(jakarta.json.stream.JsonGenerator generator, JsonpMapper mapper)
      Serialize this object to JSON.
      Specified by:
      serialize in interface JsonpSerializable
    • serializeInternal

      protected void serializeInternal(jakarta.json.stream.JsonGenerator generator, JsonpMapper mapper)
    • 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<?,?>,UpdateResponse<TDocument>,ErrorResponse> createUpdateEndpoint(JsonpDeserializer<TDocument> tDocumentDeserializer)
      Create an "update" endpoint.