Class UpdateRequest

All Implemented Interfaces:
org.apache.lucene.util.Accountable, DocWriteRequest<UpdateRequest>, IndicesRequest, WriteRequest<UpdateRequest>, Writeable, org.elasticsearch.common.util.concurrent.RefCounted, org.elasticsearch.common.xcontent.ToXContent, org.elasticsearch.common.xcontent.ToXContentObject, TaskAwareRequest

public class UpdateRequest
extends InstanceShardOperationRequest<UpdateRequest>
implements DocWriteRequest<UpdateRequest>, WriteRequest<UpdateRequest>, org.elasticsearch.common.xcontent.ToXContentObject
  • Constructor Details

    • UpdateRequest

      public UpdateRequest()
    • UpdateRequest

      public UpdateRequest​(StreamInput in) throws java.io.IOException
      Throws:
      java.io.IOException
    • UpdateRequest

      public UpdateRequest​(@Nullable ShardId shardId, StreamInput in) throws java.io.IOException
      Throws:
      java.io.IOException
    • UpdateRequest

      public UpdateRequest​(java.lang.String index, java.lang.String id)
    • UpdateRequest

      @Deprecated public UpdateRequest​(java.lang.String index, java.lang.String type, java.lang.String id)
      Deprecated.
      Types are in the process of being removed. Use UpdateRequest(String, String) instead.
  • Method Details

    • validate

      Specified by:
      validate in interface WriteRequest<UpdateRequest>
      Overrides:
      validate in class InstanceShardOperationRequest<UpdateRequest>
    • type

      @Deprecated public java.lang.String type()
      Deprecated.
      Types are in the process of being removed.
      The type of the indexed document.
      Specified by:
      type in interface DocWriteRequest<UpdateRequest>
      Returns:
      the type
    • type

      @Deprecated public UpdateRequest type​(java.lang.String type)
      Deprecated.
      Types are in the process of being removed.
      Sets the type of the indexed document.
      Specified by:
      type in interface DocWriteRequest<UpdateRequest>
      Returns:
      the Request
    • defaultTypeIfNull

      @Deprecated public UpdateRequest defaultTypeIfNull​(java.lang.String defaultType)
      Deprecated.
      Types are in the process of being removed.
      Set the default type supplied to a bulk request if this individual request's type is null or empty
      Specified by:
      defaultTypeIfNull in interface DocWriteRequest<UpdateRequest>
      Returns:
      the Request
    • id

      public java.lang.String id()
      The id of the indexed document.
      Specified by:
      id in interface DocWriteRequest<UpdateRequest>
      Returns:
      the id
    • id

      public UpdateRequest id​(java.lang.String id)
      Sets the id of the indexed document.
    • routing

      public UpdateRequest routing​(java.lang.String routing)
      Controls the shard routing of the request. Using this value to hash the shard and not the id.
      Specified by:
      routing in interface DocWriteRequest<UpdateRequest>
      Returns:
      the Request
    • routing

      public java.lang.String routing()
      Controls the shard routing of the request. Using this value to hash the shard and not the id.
      Specified by:
      routing in interface DocWriteRequest<UpdateRequest>
      Returns:
      the Routing
    • getShardId

      public ShardId getShardId()
    • script

      public Script script()
    • script

      public UpdateRequest script​(Script script)
      The script to execute. Note, make sure not to send different script each times and instead use script params if possible with the same (automatically compiled) script.
    • scriptString

      @Deprecated public java.lang.String scriptString()
      Deprecated.
      Use script() instead
    • scriptType

      @Deprecated public ScriptType scriptType()
      Deprecated.
      Use script() instead
    • scriptParams

      @Deprecated public java.util.Map<java.lang.String,​java.lang.Object> scriptParams()
      Deprecated.
      Use script() instead
    • script

      @Deprecated public UpdateRequest script​(java.lang.String script, ScriptType scriptType)
      Deprecated.
      Use script(Script) instead
      The script to execute. Note, make sure not to send different script each times and instead use script params if possible with the same (automatically compiled) script.
    • script

      @Deprecated public UpdateRequest script​(java.lang.String script)
      Deprecated.
      Use script(Script) instead
      The script to execute. Note, make sure not to send different script each times and instead use script params if possible with the same (automatically compiled) script.
    • scriptLang

      @Deprecated public UpdateRequest scriptLang​(java.lang.String scriptLang)
      Deprecated.
      Use script(Script) instead
      The language of the script to execute.
    • scriptLang

      @Deprecated public java.lang.String scriptLang()
      Deprecated.
      Use script() instead
    • addScriptParam

      @Deprecated public UpdateRequest addScriptParam​(java.lang.String name, java.lang.Object value)
      Deprecated.
      Use script(Script) instead
      Add a script parameter.
    • scriptParams

      @Deprecated public UpdateRequest scriptParams​(java.util.Map<java.lang.String,​java.lang.Object> scriptParams)
      Deprecated.
      Use script(Script) instead
      Sets the script parameters to use with the script.
    • script

      @Deprecated public UpdateRequest script​(java.lang.String script, ScriptType scriptType, @Nullable java.util.Map<java.lang.String,​java.lang.Object> scriptParams)
      Deprecated.
      Use script(Script) instead
      The script to execute. Note, make sure not to send different script each times and instead use script params if possible with the same (automatically compiled) script.
    • script

      @Deprecated public UpdateRequest script​(java.lang.String script, @Nullable java.lang.String scriptLang, ScriptType scriptType, @Nullable java.util.Map<java.lang.String,​java.lang.Object> scriptParams)
      Deprecated.
      Use script(Script) instead
      The script to execute. Note, make sure not to send different script each times and instead use script params if possible with the same (automatically compiled) script.
      Parameters:
      script - The script to execute
      scriptLang - The script language
      scriptType - The script type
      scriptParams - The script parameters
    • fetchSource

      public UpdateRequest fetchSource​(@Nullable java.lang.String include, @Nullable java.lang.String exclude)
      Indicate that _source should be returned with every hit, with an "include" and/or "exclude" set which can include simple wildcard elements.
      Parameters:
      include - An optional include (optionally wildcarded) pattern to filter the returned _source
      exclude - An optional exclude (optionally wildcarded) pattern to filter the returned _source
    • fetchSource

      public UpdateRequest fetchSource​(@Nullable java.lang.String[] includes, @Nullable java.lang.String[] excludes)
      Indicate that _source should be returned, with an "include" and/or "exclude" set which can include simple wildcard elements.
      Parameters:
      includes - An optional list of include (optionally wildcarded) pattern to filter the returned _source
      excludes - An optional list of exclude (optionally wildcarded) pattern to filter the returned _source
    • fetchSource

      public UpdateRequest fetchSource​(boolean fetchSource)
      Indicates whether the response should contain the updated _source.
    • fetchSource

      public UpdateRequest fetchSource​(FetchSourceContext context)
      Explicitly set the fetch source context for this request
    • fetchSource

      public FetchSourceContext fetchSource()
      Gets the FetchSourceContext which defines how the _source should be fetched.
    • retryOnConflict

      public UpdateRequest retryOnConflict​(int retryOnConflict)
      Sets the number of retries of a version conflict occurs because the document was updated between getting it and updating it. Defaults to 0.
    • retryOnConflict

      public int retryOnConflict()
    • version

      public UpdateRequest version​(long version)
      Description copied from interface: DocWriteRequest
      Sets the version, which will perform the operation only if a matching version exists and no changes happened on the doc since then.
      Specified by:
      version in interface DocWriteRequest<UpdateRequest>
    • version

      public long version()
      Description copied from interface: DocWriteRequest
      Get the document version for this request
      Specified by:
      version in interface DocWriteRequest<UpdateRequest>
      Returns:
      the document version
    • versionType

      public UpdateRequest versionType​(VersionType versionType)
      Description copied from interface: DocWriteRequest
      Sets the versioning type. Defaults to VersionType.INTERNAL.
      Specified by:
      versionType in interface DocWriteRequest<UpdateRequest>
    • versionType

      public VersionType versionType()
      Description copied from interface: DocWriteRequest
      Get the document version type for this request
      Specified by:
      versionType in interface DocWriteRequest<UpdateRequest>
      Returns:
      the document version type
    • setIfSeqNo

      public UpdateRequest setIfSeqNo​(long seqNo)
      only perform this update request if the document's modification was assigned the given sequence number. Must be used in combination with setIfPrimaryTerm(long) If the document last modification was assigned a different sequence number a VersionConflictEngineException will be thrown.
      Specified by:
      setIfSeqNo in interface DocWriteRequest<UpdateRequest>
    • setIfPrimaryTerm

      public UpdateRequest setIfPrimaryTerm​(long term)
      only performs this update request if the document's last modification was assigned the given primary term. Must be used in combination with setIfSeqNo(long) If the document last modification was assigned a different term a VersionConflictEngineException will be thrown.
      Specified by:
      setIfPrimaryTerm in interface DocWriteRequest<UpdateRequest>
    • ifSeqNo

      public long ifSeqNo()
      If set, only perform this update request if the document was last modification was assigned this sequence number. If the document last modification was assigned a different sequence number a VersionConflictEngineException will be thrown.
      Specified by:
      ifSeqNo in interface DocWriteRequest<UpdateRequest>
    • ifPrimaryTerm

      public long ifPrimaryTerm()
      If set, only perform this update request if the document was last modification was assigned this primary term. If the document last modification was assigned a different term a VersionConflictEngineException will be thrown.
      Specified by:
      ifPrimaryTerm in interface DocWriteRequest<UpdateRequest>
    • opType

      public DocWriteRequest.OpType opType()
      Description copied from interface: DocWriteRequest
      Get the requested document operation type of the request
      Specified by:
      opType in interface DocWriteRequest<UpdateRequest>
      Returns:
      the operation type DocWriteRequest.OpType
    • setRefreshPolicy

      public UpdateRequest setRefreshPolicy​(WriteRequest.RefreshPolicy refreshPolicy)
      Description copied from interface: WriteRequest
      Should this request trigger a refresh (WriteRequest.RefreshPolicy.IMMEDIATE), wait for a refresh ( WriteRequest.RefreshPolicy.WAIT_UNTIL), or proceed ignore refreshes entirely (WriteRequest.RefreshPolicy.NONE, the default).
      Specified by:
      setRefreshPolicy in interface WriteRequest<UpdateRequest>
    • getRefreshPolicy

      public WriteRequest.RefreshPolicy getRefreshPolicy()
      Description copied from interface: WriteRequest
      Should this request trigger a refresh (WriteRequest.RefreshPolicy.IMMEDIATE), wait for a refresh ( WriteRequest.RefreshPolicy.WAIT_UNTIL), or proceed ignore refreshes entirely (WriteRequest.RefreshPolicy.NONE, the default).
      Specified by:
      getRefreshPolicy in interface WriteRequest<UpdateRequest>
    • waitForActiveShards

      public ActiveShardCount waitForActiveShards()
    • waitForActiveShards

      public UpdateRequest waitForActiveShards​(ActiveShardCount waitForActiveShards)
      Sets the number of shard copies that must be active before proceeding with the write. See ReplicationRequest.waitForActiveShards(ActiveShardCount) for details.
    • waitForActiveShards

      public UpdateRequest waitForActiveShards​(int waitForActiveShards)
      A shortcut for waitForActiveShards(ActiveShardCount) where the numerical shard count is passed in, instead of having to first call ActiveShardCount.from(int) to get the ActiveShardCount.
    • doc

      public UpdateRequest doc​(IndexRequest doc)
      Sets the doc to use for updates when a script is not specified.
    • doc

      public UpdateRequest doc​(org.elasticsearch.common.xcontent.XContentBuilder source)
      Sets the doc to use for updates when a script is not specified.
    • doc

      public UpdateRequest doc​(java.util.Map<java.lang.String,​java.lang.Object> source)
      Sets the doc to use for updates when a script is not specified.
    • doc

      public UpdateRequest doc​(java.util.Map<java.lang.String,​java.lang.Object> source, org.elasticsearch.common.xcontent.XContentType contentType)
      Sets the doc to use for updates when a script is not specified.
    • doc

      public UpdateRequest doc​(java.lang.String source, org.elasticsearch.common.xcontent.XContentType xContentType)
      Sets the doc to use for updates when a script is not specified.
    • doc

      public UpdateRequest doc​(byte[] source, org.elasticsearch.common.xcontent.XContentType xContentType)
      Sets the doc to use for updates when a script is not specified.
    • doc

      public UpdateRequest doc​(byte[] source, int offset, int length, org.elasticsearch.common.xcontent.XContentType xContentType)
      Sets the doc to use for updates when a script is not specified.
    • doc

      public UpdateRequest doc​(java.lang.Object... source)
      Sets the doc to use for updates when a script is not specified, the doc provided is a field and value pairs.
    • doc

      public UpdateRequest doc​(org.elasticsearch.common.xcontent.XContentType xContentType, java.lang.Object... source)
      Sets the doc to use for updates when a script is not specified, the doc provided is a field and value pairs.
    • doc

      public IndexRequest doc()
    • upsert

      public UpdateRequest upsert​(IndexRequest upsertRequest)
      Sets the index request to be used if the document does not exists. Otherwise, a DocumentMissingException is thrown.
    • upsert

      public UpdateRequest upsert​(org.elasticsearch.common.xcontent.XContentBuilder source)
      Sets the doc source of the update request to be used when the document does not exists.
    • upsert

      public UpdateRequest upsert​(java.util.Map<java.lang.String,​java.lang.Object> source)
      Sets the doc source of the update request to be used when the document does not exists.
    • upsert

      public UpdateRequest upsert​(java.util.Map<java.lang.String,​java.lang.Object> source, org.elasticsearch.common.xcontent.XContentType contentType)
      Sets the doc source of the update request to be used when the document does not exists.
    • upsert

      public UpdateRequest upsert​(java.lang.String source, org.elasticsearch.common.xcontent.XContentType xContentType)
      Sets the doc source of the update request to be used when the document does not exists.
    • upsert

      public UpdateRequest upsert​(byte[] source, org.elasticsearch.common.xcontent.XContentType xContentType)
      Sets the doc source of the update request to be used when the document does not exists.
    • upsert

      public UpdateRequest upsert​(byte[] source, int offset, int length, org.elasticsearch.common.xcontent.XContentType xContentType)
      Sets the doc source of the update request to be used when the document does not exists.
    • upsert

      public UpdateRequest upsert​(java.lang.Object... source)
      Sets the doc source of the update request to be used when the document does not exists. The doc includes field and value pairs.
    • upsert

      public UpdateRequest upsert​(org.elasticsearch.common.xcontent.XContentType xContentType, java.lang.Object... source)
      Sets the doc source of the update request to be used when the document does not exists. The doc includes field and value pairs.
    • upsertRequest

      public IndexRequest upsertRequest()
    • detectNoop

      public UpdateRequest detectNoop​(boolean detectNoop)
      Should this update attempt to detect if it is a noop? Defaults to true.
      Returns:
      this for chaining
    • detectNoop

      public boolean detectNoop()
      Should this update attempt to detect if it is a noop? Defaults to true.
    • fromXContent

      public UpdateRequest fromXContent​(org.elasticsearch.common.xcontent.XContentParser parser) throws java.io.IOException
      Throws:
      java.io.IOException
    • docAsUpsert

      public boolean docAsUpsert()
    • docAsUpsert

      public UpdateRequest docAsUpsert​(boolean shouldUpsertDoc)
    • scriptedUpsert

      public boolean scriptedUpsert()
    • scriptedUpsert

      public UpdateRequest scriptedUpsert​(boolean scriptedUpsert)
    • isRequireAlias

      public boolean isRequireAlias()
      Description copied from interface: DocWriteRequest
      Should this request override specifically require the destination to be an alias?
      Specified by:
      isRequireAlias in interface DocWriteRequest<UpdateRequest>
      Returns:
      boolean flag, when true specifically requires an alias
    • setRequireAlias

      public UpdateRequest setRequireAlias​(boolean requireAlias)
    • writeTo

      public void writeTo​(StreamOutput out) throws java.io.IOException
      Description copied from interface: Writeable
      Write this into the StreamOutput.
      Specified by:
      writeTo in interface Writeable
      Overrides:
      writeTo in class InstanceShardOperationRequest<UpdateRequest>
      Throws:
      java.io.IOException
    • writeThin

      public void writeThin​(StreamOutput out) throws java.io.IOException
      Overrides:
      writeThin in class InstanceShardOperationRequest<UpdateRequest>
      Throws:
      java.io.IOException
    • toXContent

      public org.elasticsearch.common.xcontent.XContentBuilder toXContent​(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws java.io.IOException
      Specified by:
      toXContent in interface org.elasticsearch.common.xcontent.ToXContent
      Throws:
      java.io.IOException
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class TransportRequest
    • ramBytesUsed

      public long ramBytesUsed()
      Specified by:
      ramBytesUsed in interface org.apache.lucene.util.Accountable