Package org.elasticsearch.action.update
Class UpdateRequestBuilder
- java.lang.Object
-
- org.elasticsearch.action.ActionRequestBuilder<Request,Response,RequestBuilder>
-
- org.elasticsearch.action.support.single.instance.InstanceShardOperationRequestBuilder<UpdateRequest,UpdateResponse,UpdateRequestBuilder>
-
- org.elasticsearch.action.update.UpdateRequestBuilder
-
- All Implemented Interfaces:
WriteRequestBuilder<UpdateRequestBuilder>
public class UpdateRequestBuilder extends InstanceShardOperationRequestBuilder<UpdateRequest,UpdateResponse,UpdateRequestBuilder> implements WriteRequestBuilder<UpdateRequestBuilder>
-
-
Field Summary
-
Fields inherited from class org.elasticsearch.action.ActionRequestBuilder
action, client, request
-
-
Constructor Summary
Constructors Constructor Description UpdateRequestBuilder(ElasticsearchClient client, UpdateAction action)UpdateRequestBuilder(ElasticsearchClient client, UpdateAction action, java.lang.String index, java.lang.String type, java.lang.String id)
-
Method Summary
Modifier and Type Method Description UpdateRequestBuildersetDetectNoop(boolean detectNoop)Sets whether to perform extra effort to detect noop updates via docAsUpsert.UpdateRequestBuildersetDoc(byte[] source, int offset, int length, XContentType xContentType)Sets the doc to use for updates when a script is not specified.UpdateRequestBuildersetDoc(byte[] source, XContentType xContentType)Sets the doc to use for updates when a script is not specified.UpdateRequestBuildersetDoc(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.UpdateRequestBuildersetDoc(java.lang.String source, XContentType xContentType)Sets the doc to use for updates when a script is not specified.UpdateRequestBuildersetDoc(java.util.Map source)Sets the doc to use for updates when a script is not specified.UpdateRequestBuildersetDoc(java.util.Map source, XContentType contentType)Sets the doc to use for updates when a script is not specified.UpdateRequestBuildersetDoc(IndexRequest indexRequest)Sets the doc to use for updates when a script is not specified.UpdateRequestBuildersetDoc(XContentBuilder source)Sets the doc to use for updates when a script is not specified.UpdateRequestBuildersetDoc(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.UpdateRequestBuildersetDocAsUpsert(boolean shouldUpsertDoc)Sets whether the specified doc parameter should be used as upsert document.UpdateRequestBuildersetFetchSource(boolean fetchSource)Indicates whether the response should contain the updated _source.UpdateRequestBuildersetFetchSource(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.UpdateRequestBuildersetFetchSource(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.UpdateRequestBuildersetFields(java.lang.String... fields)Deprecated.UsesetFetchSource(String[], String[])insteadUpdateRequestBuildersetId(java.lang.String id)Sets the id of the indexed document.UpdateRequestBuildersetIfPrimaryTerm(long term)only perform this update request if the document was last modification was assigned the given primary term.UpdateRequestBuildersetIfSeqNo(long seqNo)only perform this update request if the document was last modification was assigned the given sequence number.UpdateRequestBuildersetParent(java.lang.String parent)UpdateRequestBuildersetRetryOnConflict(int retryOnConflict)Sets the number of retries of a version conflict occurs because the document was updated between getting it and updating it.UpdateRequestBuildersetRouting(java.lang.String routing)Controls the shard routing of the request.UpdateRequestBuildersetScript(Script script)The script to execute.UpdateRequestBuildersetScriptedUpsert(boolean scriptedUpsert)Sets whether the script should be run in the case of an insertUpdateRequestBuildersetType(java.lang.String type)Sets the type of the indexed document.UpdateRequestBuildersetUpsert(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.UpdateRequestBuildersetUpsert(byte[] source, XContentType xContentType)Sets the doc source of the update request to be used when the document does not exists.UpdateRequestBuildersetUpsert(java.lang.Object... source)Sets the doc source of the update request to be used when the document does not exists.UpdateRequestBuildersetUpsert(java.lang.String source, XContentType xContentType)Sets the doc source of the update request to be used when the document does not exists.UpdateRequestBuildersetUpsert(java.util.Map source)Sets the doc source of the update request to be used when the document does not exists.UpdateRequestBuildersetUpsert(java.util.Map source, XContentType contentType)Sets the doc source of the update request to be used when the document does not exists.UpdateRequestBuildersetUpsert(IndexRequest indexRequest)Sets the index request to be used if the document does not exists.UpdateRequestBuildersetUpsert(XContentBuilder source)Sets the doc source of the update request to be used when the document does not exists.UpdateRequestBuildersetUpsert(XContentType xContentType, java.lang.Object... source)Sets the doc source of the update request to be used when the document does not exists.UpdateRequestBuildersetVersion(long version)Sets the version, which will cause the index operation to only be performed if a matching version exists and no changes happened on the doc since then.UpdateRequestBuildersetVersionType(VersionType versionType)Sets the versioning type.UpdateRequestBuildersetWaitForActiveShards(int waitForActiveShards)A shortcut forsetWaitForActiveShards(ActiveShardCount)where the numerical shard count is passed in, instead of having to first callActiveShardCount.from(int)to get the ActiveShardCount.UpdateRequestBuildersetWaitForActiveShards(ActiveShardCount waitForActiveShards)Sets the number of shard copies that must be active before proceeding with the write.-
Methods inherited from class org.elasticsearch.action.support.single.instance.InstanceShardOperationRequestBuilder
setIndex, setTimeout, setTimeout
-
Methods inherited from class org.elasticsearch.action.ActionRequestBuilder
execute, execute, get, get, get, request
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.action.support.WriteRequestBuilder
request, setRefreshPolicy, setRefreshPolicy
-
-
-
-
Constructor Detail
-
UpdateRequestBuilder
public UpdateRequestBuilder(ElasticsearchClient client, UpdateAction action)
-
UpdateRequestBuilder
public UpdateRequestBuilder(ElasticsearchClient client, UpdateAction action, java.lang.String index, java.lang.String type, java.lang.String id)
-
-
Method Detail
-
setType
public UpdateRequestBuilder setType(java.lang.String type)
Sets the type of the indexed document.
-
setId
public UpdateRequestBuilder setId(java.lang.String id)
Sets the id of the indexed document.
-
setRouting
public UpdateRequestBuilder setRouting(java.lang.String routing)
Controls the shard routing of the request. Using this value to hash the shard and not the id.
-
setParent
public UpdateRequestBuilder setParent(java.lang.String parent)
-
setScript
public UpdateRequestBuilder setScript(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.The script works with the variable
ctx, which is bound to the entry, e.g.ctx._source.mycounter += 1.
-
setFields
@Deprecated public UpdateRequestBuilder setFields(java.lang.String... fields)
Deprecated.UsesetFetchSource(String[], String[])insteadExplicitly specify the fields that will be returned. By default, nothing is returned.
-
setFetchSource
public UpdateRequestBuilder setFetchSource(@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
-
setFetchSource
public UpdateRequestBuilder setFetchSource(@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
-
setFetchSource
public UpdateRequestBuilder setFetchSource(boolean fetchSource)
Indicates whether the response should contain the updated _source.
-
setRetryOnConflict
public UpdateRequestBuilder setRetryOnConflict(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.
-
setVersion
public UpdateRequestBuilder setVersion(long version)
Sets the version, which will cause the index operation to only be performed if a matching version exists and no changes happened on the doc since then.
-
setVersionType
public UpdateRequestBuilder setVersionType(VersionType versionType)
Sets the versioning type. Defaults toVersionType.INTERNAL.
-
setIfSeqNo
public UpdateRequestBuilder setIfSeqNo(long seqNo)
only perform this update request if the document was last 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.
-
setIfPrimaryTerm
public UpdateRequestBuilder setIfPrimaryTerm(long term)
only perform this update request if the document was 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.
-
setWaitForActiveShards
public UpdateRequestBuilder setWaitForActiveShards(ActiveShardCount waitForActiveShards)
Sets the number of shard copies that must be active before proceeding with the write. SeeReplicationRequest.waitForActiveShards(ActiveShardCount)for details.
-
setWaitForActiveShards
public UpdateRequestBuilder setWaitForActiveShards(int waitForActiveShards)
A shortcut forsetWaitForActiveShards(ActiveShardCount)where the numerical shard count is passed in, instead of having to first callActiveShardCount.from(int)to get the ActiveShardCount.
-
setDoc
public UpdateRequestBuilder setDoc(IndexRequest indexRequest)
Sets the doc to use for updates when a script is not specified.
-
setDoc
public UpdateRequestBuilder setDoc(XContentBuilder source)
Sets the doc to use for updates when a script is not specified.
-
setDoc
public UpdateRequestBuilder setDoc(java.util.Map source)
Sets the doc to use for updates when a script is not specified.
-
setDoc
public UpdateRequestBuilder setDoc(java.util.Map source, XContentType contentType)
Sets the doc to use for updates when a script is not specified.
-
setDoc
public UpdateRequestBuilder setDoc(java.lang.String source, XContentType xContentType)
Sets the doc to use for updates when a script is not specified.
-
setDoc
public UpdateRequestBuilder setDoc(byte[] source, XContentType xContentType)
Sets the doc to use for updates when a script is not specified.
-
setDoc
public UpdateRequestBuilder setDoc(byte[] source, int offset, int length, XContentType xContentType)
Sets the doc to use for updates when a script is not specified.
-
setDoc
public UpdateRequestBuilder setDoc(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.
-
setDoc
public UpdateRequestBuilder setDoc(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.
-
setUpsert
public UpdateRequestBuilder setUpsert(IndexRequest indexRequest)
Sets the index request to be used if the document does not exists. Otherwise, aDocumentMissingExceptionis thrown.
-
setUpsert
public UpdateRequestBuilder setUpsert(XContentBuilder source)
Sets the doc source of the update request to be used when the document does not exists.
-
setUpsert
public UpdateRequestBuilder setUpsert(java.util.Map source)
Sets the doc source of the update request to be used when the document does not exists.
-
setUpsert
public UpdateRequestBuilder setUpsert(java.util.Map source, XContentType contentType)
Sets the doc source of the update request to be used when the document does not exists.
-
setUpsert
public UpdateRequestBuilder setUpsert(java.lang.String source, XContentType xContentType)
Sets the doc source of the update request to be used when the document does not exists.
-
setUpsert
public UpdateRequestBuilder setUpsert(byte[] source, XContentType xContentType)
Sets the doc source of the update request to be used when the document does not exists.
-
setUpsert
public UpdateRequestBuilder setUpsert(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.
-
setUpsert
public UpdateRequestBuilder setUpsert(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.
-
setUpsert
public UpdateRequestBuilder setUpsert(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.
-
setDocAsUpsert
public UpdateRequestBuilder setDocAsUpsert(boolean shouldUpsertDoc)
Sets whether the specified doc parameter should be used as upsert document.
-
setDetectNoop
public UpdateRequestBuilder setDetectNoop(boolean detectNoop)
Sets whether to perform extra effort to detect noop updates via docAsUpsert. Defaults to true.
-
setScriptedUpsert
public UpdateRequestBuilder setScriptedUpsert(boolean scriptedUpsert)
Sets whether the script should be run in the case of an insert
-
-