Package org.elasticsearch.action.update
Class UpdateRequest
- java.lang.Object
-
- All Implemented Interfaces:
DocWriteRequest<UpdateRequest>,IndicesRequest,WriteRequest<UpdateRequest>,Streamable,Writeable,ToXContent,ToXContentObject,TaskAwareRequest
public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest> implements DocWriteRequest<UpdateRequest>, WriteRequest<UpdateRequest>, ToXContentObject
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.elasticsearch.transport.TransportRequest
TransportRequest.Empty
-
Nested classes/interfaces inherited from interface org.elasticsearch.action.DocWriteRequest
DocWriteRequest.OpType
-
Nested classes/interfaces inherited from interface org.elasticsearch.action.IndicesRequest
IndicesRequest.Replaceable
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
Nested classes/interfaces inherited from interface org.elasticsearch.action.support.WriteRequest
WriteRequest.RefreshPolicy
-
-
Field Summary
-
Fields inherited from class org.elasticsearch.action.support.single.instance.InstanceShardOperationRequest
DEFAULT_TIMEOUT, index, shardId, timeout
-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Constructor Summary
Constructors Constructor Description UpdateRequest()UpdateRequest(java.lang.String index, java.lang.String type, java.lang.String id)
-
Method Summary
Modifier and Type Method Description UpdateRequestaddScriptParam(java.lang.String name, java.lang.Object value)Deprecated.Usescript(Script)insteadbooleandetectNoop()Should this update attempt to detect if it is a noop? Defaults to true.UpdateRequestdetectNoop(boolean detectNoop)Should this update attempt to detect if it is a noop? Defaults to true.IndexRequestdoc()UpdateRequestdoc(byte[] source, int offset, int length, XContentType xContentType)Sets the doc to use for updates when a script is not specified.UpdateRequestdoc(byte[] source, XContentType xContentType)Sets the doc to use for updates when a script is not specified.UpdateRequestdoc(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.UpdateRequestdoc(java.lang.String source, XContentType xContentType)Sets the doc to use for updates when a script is not specified.UpdateRequestdoc(java.util.Map source)Sets the doc to use for updates when a script is not specified.UpdateRequestdoc(java.util.Map source, XContentType contentType)Sets the doc to use for updates when a script is not specified.UpdateRequestdoc(IndexRequest doc)Sets the doc to use for updates when a script is not specified.UpdateRequestdoc(XContentBuilder source)Sets the doc to use for updates when a script is not specified.UpdateRequestdoc(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.booleandocAsUpsert()UpdateRequestdocAsUpsert(boolean shouldUpsertDoc)FetchSourceContextfetchSource()Gets theFetchSourceContextwhich defines how the _source should be fetched.UpdateRequestfetchSource(boolean fetchSource)Indicates whether the response should contain the updated _source.UpdateRequestfetchSource(java.lang.String[] includes, java.lang.String[] excludes)Indicate that _source should be returned, with an "include" and/or "exclude" set which can include simple wildcard elements.UpdateRequestfetchSource(java.lang.String include, 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.UpdateRequestfetchSource(FetchSourceContext context)Explicitly set the fetch source context for this requestjava.lang.String[]fields()Deprecated.UsefetchSource()insteadUpdateRequestfields(java.lang.String... fields)Deprecated.UsefetchSource(String[], String[])insteadUpdateRequestfromXContent(XContentParser parser)WriteRequest.RefreshPolicygetRefreshPolicy()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).ShardIdgetShardId()java.lang.Stringid()The id of the indexed document.UpdateRequestid(java.lang.String id)Sets the id of the indexed document.longifPrimaryTerm()If set, only perform this update request if the document was last modification was assigned this primary term.longifSeqNo()If set, only perform this update request if the document was last modification was assigned this sequence number.DocWriteRequest.OpTypeopType()Get the requested document operation type of the requestjava.lang.Stringparent()Get the parent for this requestUpdateRequestparent(java.lang.String parent)The parent id is used for the upsert request.voidreadFrom(StreamInput in)Set this object's fields from a StreamInput.intretryOnConflict()UpdateRequestretryOnConflict(int retryOnConflict)Sets the number of retries of a version conflict occurs because the document was updated between getting it and updating it.java.lang.Stringrouting()Controls the shard routing of the request.UpdateRequestrouting(java.lang.String routing)Controls the shard routing of the request.Scriptscript()UpdateRequestscript(java.lang.String script)Deprecated.Usescript(Script)insteadUpdateRequestscript(java.lang.String script, java.lang.String scriptLang, ScriptType scriptType, java.util.Map<java.lang.String,java.lang.Object> scriptParams)Deprecated.Usescript(Script)insteadUpdateRequestscript(java.lang.String script, ScriptType scriptType)Deprecated.Usescript(Script)insteadUpdateRequestscript(java.lang.String script, ScriptType scriptType, java.util.Map<java.lang.String,java.lang.Object> scriptParams)Deprecated.Usescript(Script)insteadUpdateRequestscript(Script script)The script to execute.booleanscriptedUpsert()UpdateRequestscriptedUpsert(boolean scriptedUpsert)java.lang.StringscriptLang()Deprecated.Usescript()insteadUpdateRequestscriptLang(java.lang.String scriptLang)Deprecated.Usescript(Script)insteadjava.util.Map<java.lang.String,java.lang.Object>scriptParams()Deprecated.Usescript()insteadUpdateRequestscriptParams(java.util.Map<java.lang.String,java.lang.Object> scriptParams)Deprecated.Usescript(Script)insteadjava.lang.StringscriptString()Deprecated.Usescript()insteadScriptTypescriptType()Deprecated.Usescript()insteadUpdateRequestsetIfPrimaryTerm(long term)only performs this update request if the document's last modification was assigned the given primary term.UpdateRequestsetIfSeqNo(long seqNo)only perform this update request if the document's modification was assigned the given sequence number.UpdateRequestsetRefreshPolicy(WriteRequest.RefreshPolicy refreshPolicy)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).java.lang.StringtoString()XContentBuildertoXContent(XContentBuilder builder, ToXContent.Params params)java.lang.Stringtype()The type of the indexed document.UpdateRequesttype(java.lang.String type)Sets the type of the indexed document.UpdateRequestupsert(byte[] source, int offset, int length, XContentType xContentType)Sets the doc source of the update request to be used when the document does not exists.UpdateRequestupsert(byte[] source, XContentType xContentType)Sets the doc source of the update request to be used when the document does not exists.UpdateRequestupsert(java.lang.Object... source)Sets the doc source of the update request to be used when the document does not exists.UpdateRequestupsert(java.lang.String source, XContentType xContentType)Sets the doc source of the update request to be used when the document does not exists.UpdateRequestupsert(java.util.Map source)Sets the doc source of the update request to be used when the document does not exists.UpdateRequestupsert(java.util.Map source, XContentType contentType)Sets the doc source of the update request to be used when the document does not exists.UpdateRequestupsert(IndexRequest upsertRequest)Sets the index request to be used if the document does not exists.UpdateRequestupsert(XContentBuilder source)Sets the doc source of the update request to be used when the document does not exists.UpdateRequestupsert(XContentType xContentType, java.lang.Object... source)Sets the doc source of the update request to be used when the document does not exists.IndexRequestupsertRequest()ActionRequestValidationExceptionvalidate()longversion()Get the document version for this requestUpdateRequestversion(long version)Sets the version, which will perform the operation only if a matching version exists and no changes happened on the doc since then.VersionTypeversionType()Get the document version type for this requestUpdateRequestversionType(VersionType versionType)Sets the versioning type.ActiveShardCountwaitForActiveShards()UpdateRequestwaitForActiveShards(int waitForActiveShards)A shortcut forwaitForActiveShards(ActiveShardCount)where the numerical shard count is passed in, instead of having to first callActiveShardCount.from(int)to get the ActiveShardCount.UpdateRequestwaitForActiveShards(ActiveShardCount waitForActiveShards)Sets the number of shard copies that must be active before proceeding with the write.voidwriteTo(StreamOutput out)Write this object's fields to a StreamOutput.-
Methods inherited from class org.elasticsearch.action.support.single.instance.InstanceShardOperationRequest
concreteIndex, index, index, indices, indicesOptions, timeout, timeout, timeout
-
Methods inherited from class org.elasticsearch.action.ActionRequest
getShouldStoreResult
-
Methods inherited from class org.elasticsearch.transport.TransportRequest
getParentTask, setParentTask
-
Methods inherited from class org.elasticsearch.transport.TransportMessage
remoteAddress, remoteAddress
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.action.DocWriteRequest
index, index, indicesOptions
-
Methods inherited from interface org.elasticsearch.action.IndicesRequest
indices
-
Methods inherited from interface org.elasticsearch.tasks.TaskAwareRequest
createTask, getDescription, setParentTask
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
Methods inherited from interface org.elasticsearch.action.support.WriteRequest
setRefreshPolicy
-
-
-
-
Method Detail
-
validate
public ActionRequestValidationException validate()
- Specified by:
validatein interfaceWriteRequest<UpdateRequest>- Overrides:
validatein classInstanceShardOperationRequest<UpdateRequest>
-
type
public java.lang.String type()
The type of the indexed document.- Specified by:
typein interfaceDocWriteRequest<UpdateRequest>- Returns:
- the type
-
type
public UpdateRequest type(java.lang.String type)
Sets the type of the indexed document.- Specified by:
typein interfaceDocWriteRequest<UpdateRequest>- Returns:
- the Request
-
id
public java.lang.String id()
The id of the indexed document.- Specified by:
idin interfaceDocWriteRequest<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:
routingin interfaceDocWriteRequest<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:
routingin interfaceDocWriteRequest<UpdateRequest>- Returns:
- the Routing
-
parent
public UpdateRequest parent(java.lang.String parent)
The parent id is used for the upsert request.
-
parent
public java.lang.String parent()
Description copied from interface:DocWriteRequestGet the parent for this request- Specified by:
parentin interfaceDocWriteRequest<UpdateRequest>- Returns:
- the Parent
-
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.Usescript()instead
-
scriptType
@Deprecated public ScriptType scriptType()
Deprecated.Usescript()instead
-
scriptParams
@Deprecated public java.util.Map<java.lang.String,java.lang.Object> scriptParams()
Deprecated.Usescript()instead
-
script
@Deprecated public UpdateRequest script(java.lang.String script, ScriptType scriptType)
Deprecated.Usescript(Script)insteadThe 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.Usescript(Script)insteadThe 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.Usescript(Script)insteadThe language of the script to execute.
-
scriptLang
@Deprecated public java.lang.String scriptLang()
Deprecated.Usescript()instead
-
addScriptParam
@Deprecated public UpdateRequest addScriptParam(java.lang.String name, java.lang.Object value)
Deprecated.Usescript(Script)insteadAdd a script parameter.
-
scriptParams
@Deprecated public UpdateRequest scriptParams(java.util.Map<java.lang.String,java.lang.Object> scriptParams)
Deprecated.Usescript(Script)insteadSets 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.Usescript(Script)insteadThe 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.Usescript(Script)insteadThe 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 executescriptLang- The script languagescriptType- The script typescriptParams- The script parameters
-
fields
@Deprecated public UpdateRequest fields(java.lang.String... fields)
Deprecated.UsefetchSource(String[], String[])insteadExplicitly specify the fields that will be returned. By default, nothing is returned.
-
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 _sourceexclude- 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 _sourceexcludes- 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
-
fields
@Deprecated public java.lang.String[] fields()
Deprecated.UsefetchSource()insteadGet the fields to be returned.
-
fetchSource
public FetchSourceContext fetchSource()
Gets theFetchSourceContextwhich 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:DocWriteRequestSets the version, which will perform the operation only if a matching version exists and no changes happened on the doc since then.- Specified by:
versionin interfaceDocWriteRequest<UpdateRequest>
-
version
public long version()
Description copied from interface:DocWriteRequestGet the document version for this request- Specified by:
versionin interfaceDocWriteRequest<UpdateRequest>- Returns:
- the document version
-
versionType
public UpdateRequest versionType(VersionType versionType)
Description copied from interface:DocWriteRequestSets the versioning type. Defaults toVersionType.INTERNAL.- Specified by:
versionTypein interfaceDocWriteRequest<UpdateRequest>
-
versionType
public VersionType versionType()
Description copied from interface:DocWriteRequestGet the document version type for this request- Specified by:
versionTypein interfaceDocWriteRequest<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 withsetIfPrimaryTerm(long)If the document last modification was assigned a different sequence number aVersionConflictEngineExceptionwill be thrown.- Specified by:
setIfSeqNoin interfaceDocWriteRequest<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 withsetIfSeqNo(long)If the document last modification was assigned a different term aVersionConflictEngineExceptionwill be thrown.- Specified by:
setIfPrimaryTermin interfaceDocWriteRequest<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 aVersionConflictEngineExceptionwill be thrown.- Specified by:
ifSeqNoin interfaceDocWriteRequest<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 aVersionConflictEngineExceptionwill be thrown.- Specified by:
ifPrimaryTermin interfaceDocWriteRequest<UpdateRequest>
-
opType
public DocWriteRequest.OpType opType()
Description copied from interface:DocWriteRequestGet the requested document operation type of the request- Specified by:
opTypein interfaceDocWriteRequest<UpdateRequest>- Returns:
- the operation type
DocWriteRequest.OpType
-
setRefreshPolicy
public UpdateRequest setRefreshPolicy(WriteRequest.RefreshPolicy refreshPolicy)
Description copied from interface:WriteRequestShould 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:
setRefreshPolicyin interfaceWriteRequest<UpdateRequest>
-
getRefreshPolicy
public WriteRequest.RefreshPolicy getRefreshPolicy()
Description copied from interface:WriteRequestShould 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:
getRefreshPolicyin interfaceWriteRequest<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. SeeReplicationRequest.waitForActiveShards(ActiveShardCount)for details.
-
waitForActiveShards
public UpdateRequest waitForActiveShards(int waitForActiveShards)
A shortcut forwaitForActiveShards(ActiveShardCount)where the numerical shard count is passed in, instead of having to first callActiveShardCount.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(XContentBuilder source)
Sets the doc to use for updates when a script is not specified.
-
doc
public UpdateRequest doc(java.util.Map source)
Sets the doc to use for updates when a script is not specified.
-
doc
public UpdateRequest doc(java.util.Map source, XContentType contentType)
Sets the doc to use for updates when a script is not specified.
-
doc
public UpdateRequest doc(java.lang.String source, XContentType xContentType)
Sets the doc to use for updates when a script is not specified.
-
doc
public UpdateRequest doc(byte[] source, 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, 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(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, aDocumentMissingExceptionis thrown.
-
upsert
public UpdateRequest upsert(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 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 source, 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, 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, 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, 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(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(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)
-
readFrom
public void readFrom(StreamInput in) throws java.io.IOException
Description copied from interface:StreamableSet this object's fields from a StreamInput.- Specified by:
readFromin interfaceStreamable- Overrides:
readFromin classInstanceShardOperationRequest<UpdateRequest>- Throws:
java.io.IOException
-
writeTo
public void writeTo(StreamOutput out) throws java.io.IOException
Description copied from interface:StreamableWrite this object's fields to a StreamOutput.- Specified by:
writeToin interfaceStreamable- Specified by:
writeToin interfaceWriteable- Overrides:
writeToin classInstanceShardOperationRequest<UpdateRequest>- Throws:
java.io.IOException
-
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Specified by:
toXContentin interfaceToXContent- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-