- All Implemented Interfaces:
org.apache.lucene.util.Accountable,CompositeIndicesRequest,DocWriteRequest<IndexRequest>,IndicesRequest,WriteRequest<IndexRequest>,Writeable,RefCounted,TaskAwareRequest,TransportRequest
The index requires the ReplicationRequest.index(), id(String) and
source(byte[], XContentType) to be set.
The source (content to index) can be set in its bytes form using (source(byte[], XContentType)),
its string form (source(String, XContentType)) or using a XContentBuilder
(source(org.elasticsearch.xcontent.XContentBuilder)).
If the id(String) is not set, it will be automatically generated.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.elasticsearch.action.DocWriteRequest
DocWriteRequest.OpTypeNested classes/interfaces inherited from interface org.elasticsearch.action.IndicesRequest
IndicesRequest.RemoteClusterShardRequest, IndicesRequest.Replaceable, IndicesRequest.SingleIndexNoWildcardsNested 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
FieldsModifier and TypeFieldDescriptionstatic final intMaximal allowed length (in bytes) of the document ID.static final longValue forgetAutoGeneratedTimestamp()if the document has an external provided ID.Fields inherited from class org.elasticsearch.action.support.replication.ReplicationRequest
DEFAULT_TIMEOUT, index, shardId, timeout, waitForActiveShardsFields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLEFields inherited from interface org.elasticsearch.action.DocWriteRequest
LIST_EXECUTED_PIPELINES, REQUIRE_ALIAS, REQUIRE_DATA_STREAMFields inherited from interface org.elasticsearch.core.RefCounted
ALWAYS_REFERENCED -
Constructor Summary
ConstructorsConstructorDescriptionIndexRequest(String index) Constructs a new index request against the specific index.IndexRequest(ShardId shardId, StreamInput in) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPipeline(String pipeline) Adds the pipeline to the list of executed pipelines, if listExecutedPipelines is truevoidSet the#id()to an automatically generated one and make this request compatible with the append-only optimization.voidvoidSet the#id()to an automatically generated one, optimized for storage (compression) efficiency.create(boolean create) Set totrueto force this index to useDocWriteRequest.OpType.CREATE.longReturns the timestamp the auto generated ID was created or -1L if the document has no auto generated timestamp.getConcreteWriteIndex(IndexAbstraction ia, ProjectMetadata project) Resolves the write index that should receive this request based on the provided index abstraction.The content type.Returns a map from the full path of field names to the name of dynamic mapping templates.This returns the list of pipelines executed on the document for this request.Returns the final ingest pipeline to be executed before indexing the document.booleanbooleanReturns the ingest pipeline to be executed before indexing the documentstatic XContentBuildergetXContentBuilder(XContentType xContentType, Object... source) Returns an XContentBuilder for the given xContentType and source arrayid()The id of the indexed document.Sets the id of the indexed document.longIf set, only perform this indexing request if the document was last modification was assigned this primary term.longifSeqNo()If set, only perform this indexing request if the document was last modification was assigned this sequence number.booleanDetermines whether the request should be applied to data streams.booleanReturns whether or not the pipeline for this request has been resolved by the coordinating node.isPipelineResolved(boolean isPipelineResolved) Sets if the pipeline for this request has been resolved by the coordinating node.booleanShould this request override specifically require the destination to be an alias?booleanShould this request override specifically require the destination to be a data stream?booleanisRetry()Returnstrueif this request has been sent to a shard copy more than once.booleanReturns a transient flag denoting that the local request should be routed to a failure store.voidonRetry()This method is called before this replication request is retried the first time.opType()Get the requested document operation type of the requestSets a string representation of theopType(OpType).opType(DocWriteRequest.OpType opType) Sets the type of operation to perform.voidpostRoutingProcess(IndexRouting indexRouting) Finalize the request after routing it.voidpreRoutingProcess(IndexRouting indexRouting) Finalize the request before routing it.longvoidreset()Resets thisIndexRequestclass, so that in case this instance can be used by the bulk/index action if it was already used before.introute(IndexRouting indexRouting) Pick the appropriate shard id to receive this request.routing()Controls the shard routing of the request.Controls the shard routing of the request.setDynamicTemplates(Map<String, String> dynamicTemplates) Specifies a map from the full path of field names to the name of dynamic mapping templatessetFinalPipeline(String finalPipeline) Sets the final ingest pipeline to be executed before indexing the document.setIfPrimaryTerm(long term) only performs this indexing request if the document was last modification was assigned the given primary term.setIfSeqNo(long seqNo) only perform this indexing request if the document was last modification was assigned the given sequence number.setIncludeSourceOnError(boolean includeSourceOnError) setListExecutedPipelines(boolean listExecutedPipelines) setPipeline(String pipeline) Sets the ingest pipeline to be executed before indexing the documentvoidsetRawTimestamp(Object rawTimestamp) setRequireAlias(boolean requireAlias) setRequireDataStream(boolean requireDataStream) Set whether this IndexRequest requires a data stream.setWriteToFailureStore(boolean writeToFailureStore) Sets a transient flag denoting that the local request should be routed to a failure store.source()The source of the document to index, recopied to a new array if it is unsafe.source(byte[] source, int offset, int length, XContentType xContentType) Sets the document to index in bytes form (assumed to be safe to be used from different threads).source(byte[] source, XContentType xContentType) Sets the document to index in bytes form.Sets the content source to index using the default content type (Requests.INDEX_CONTENT_TYPE)source(String source, XContentType xContentType) Sets the document source to index.Index the Map inRequests.INDEX_CONTENT_TYPEformatsource(Map<String, ?> source, XContentType contentType) Index the Map as the provided content type.source(Map<String, ?> source, XContentType contentType, boolean ensureNoSelfReferences) source(BytesReference source, XContentType xContentType) Sets the document to index in bytes form.source(XContentBuilder sourceBuilder) Sets the content source to index.source(XContentType xContentType, Object... source) Sets the content source to index.sourceAsMap(XContentParserDecorator parserDecorator) toString()validate()longversion()Returns stored version.version(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.Get the document version type for this requestversionType(VersionType versionType) Sets the versioning type.voidwriteThin(StreamOutput out) Thin serialization that does not writeReplicationRequest.shardIdand will only writeReplicationRequest.indexif it is different from the index name inReplicationRequest.shardId.voidwriteTo(StreamOutput out) Write this into the StreamOutput.Methods inherited from class org.elasticsearch.action.support.replication.ReplicatedWriteRequest
getRefreshPolicy, setRefreshPolicyMethods inherited from class org.elasticsearch.action.support.replication.ReplicationRequest
createTask, getDescription, index, index, indices, indicesOptions, routedBasedOnClusterVersion, shardId, timeout, timeout, waitForActiveShards, waitForActiveShards, waitForActiveShardsMethods inherited from class org.elasticsearch.action.ActionRequest
getShouldStoreResultMethods inherited from class org.elasticsearch.transport.AbstractTransportRequest
getParentTask, getRequestId, remoteAddress, remoteAddress, setParentTask, setRequestIdMethods inherited from class org.elasticsearch.transport.TransportMessage
decRef, hasReferences, incRef, tryIncRefMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.lucene.util.Accountable
getChildResourcesMethods inherited from interface org.elasticsearch.action.DocWriteRequest
index, index, indicesOptionsMethods inherited from interface org.elasticsearch.action.IndicesRequest
indicesMethods inherited from interface org.elasticsearch.core.RefCounted
decRef, hasReferences, incRef, mustIncRef, tryIncRefMethods inherited from interface org.elasticsearch.tasks.TaskAwareRequest
createTask, setParentTaskMethods inherited from interface org.elasticsearch.action.support.WriteRequest
setRefreshPolicy
-
Field Details
-
MAX_DOCUMENT_ID_LENGTH_IN_BYTES
public static final int MAX_DOCUMENT_ID_LENGTH_IN_BYTESMaximal allowed length (in bytes) of the document ID.- See Also:
-
UNSET_AUTO_GENERATED_TIMESTAMP
public static final long UNSET_AUTO_GENERATED_TIMESTAMPValue forgetAutoGeneratedTimestamp()if the document has an external provided ID.- See Also:
-
-
Constructor Details
-
IndexRequest
- Throws:
IOException
-
IndexRequest
- Throws:
IOException
-
IndexRequest
public IndexRequest() -
IndexRequest
Constructs a new index request against the specific index. Thesource(byte[], XContentType)must be set.
-
-
Method Details
-
validate
- Specified by:
validatein interfaceWriteRequest<IndexRequest>- Overrides:
validatein classReplicationRequest<IndexRequest>
-
getContentType
The content type. This will be used when generating a document from user provided objects like Maps and when parsing the source at index time -
id
The id of the indexed document. If not set, will be automatically generated.- Specified by:
idin interfaceDocWriteRequest<IndexRequest>- Returns:
- the id
-
id
Sets the id of the indexed document. If not set, will be automatically generated. -
routing
Controls the shard routing of the request. Using this value to hash the shard and not the id.- Specified by:
routingin interfaceDocWriteRequest<IndexRequest>- Returns:
- the Request
-
routing
Controls the shard routing of the request. Using this value to hash the shard and not the id.- Specified by:
routingin interfaceDocWriteRequest<IndexRequest>- Returns:
- the Routing
-
setPipeline
Sets the ingest pipeline to be executed before indexing the document -
getPipeline
Returns the ingest pipeline to be executed before indexing the document -
setFinalPipeline
Sets the final ingest pipeline to be executed before indexing the document.- Parameters:
finalPipeline- the name of the final pipeline- Returns:
- this index request
-
getFinalPipeline
Returns the final ingest pipeline to be executed before indexing the document.- Returns:
- the name of the final pipeline
-
isPipelineResolved
Sets if the pipeline for this request has been resolved by the coordinating node.- Parameters:
isPipelineResolved- true if the pipeline has been resolved- Returns:
- the request
-
isPipelineResolved
public boolean isPipelineResolved()Returns whether or not the pipeline for this request has been resolved by the coordinating node.- Returns:
- true if the pipeline has been resolved
-
source
The source of the document to index, recopied to a new array if it is unsafe. -
sourceAsMap
-
sourceAsMap
-
source
Index the Map inRequests.INDEX_CONTENT_TYPEformat- Parameters:
source- The map to index- Throws:
ElasticsearchGenerationException
-
source
public IndexRequest source(Map<String, ?> source, XContentType contentType) throws ElasticsearchGenerationExceptionIndex the Map as the provided content type.- Parameters:
source- The map to index- Throws:
ElasticsearchGenerationException
-
source
public IndexRequest source(Map<String, ?> source, XContentType contentType, boolean ensureNoSelfReferences) throws ElasticsearchGenerationException- Throws:
ElasticsearchGenerationException
-
source
Sets the document source to index.Note, its preferable to either set it using
source(org.elasticsearch.xcontent.XContentBuilder)or using thesource(byte[], XContentType). -
source
Sets the content source to index. -
source
Sets the content source to index using the default content type (Requests.INDEX_CONTENT_TYPE)Note: the number of objects passed to this method must be an even number. Also the first argument in each pair (the field name) must have a valid String representation.
-
source
Sets the content source to index.Note: the number of objects passed to this method as varargs must be an even number. Also the first argument in each pair (the field name) must have a valid String representation.
-
getXContentBuilder
Returns an XContentBuilder for the given xContentType and source arrayNote: the number of objects passed to this method as varargs must be an even number. Also the first argument in each pair (the field name) must have a valid String representation.
-
source
Sets the document to index in bytes form. -
source
Sets the document to index in bytes form. -
source
Sets the document to index in bytes form (assumed to be safe to be used from different threads).- Parameters:
source- The source to indexoffset- The offset in the byte arraylength- The length of the data
-
opType
Sets the type of operation to perform. -
opType
Sets a string representation of theopType(OpType). Can be either "index" or "create". -
create
Set totrueto force this index to useDocWriteRequest.OpType.CREATE. -
opType
Description copied from interface:DocWriteRequestGet the requested document operation type of the request- Specified by:
opTypein interfaceDocWriteRequest<IndexRequest>- Returns:
- the operation type
DocWriteRequest.OpType
-
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<IndexRequest>
-
version
public long version()Returns stored version. If currently stored version isVersions.MATCH_ANYand opType isDocWriteRequest.OpType.CREATE, returnsVersions.MATCH_DELETED.- Specified by:
versionin interfaceDocWriteRequest<IndexRequest>- Returns:
- the document version
-
versionType
Description copied from interface:DocWriteRequestSets the versioning type. Defaults toVersionType.INTERNAL.- Specified by:
versionTypein interfaceDocWriteRequest<IndexRequest>
-
setIfSeqNo
only perform this indexing 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 a
VersionConflictEngineExceptionwill be thrown.- Specified by:
setIfSeqNoin interfaceDocWriteRequest<IndexRequest>
-
setIfPrimaryTerm
only performs this indexing 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 a
VersionConflictEngineExceptionwill be thrown.- Specified by:
setIfPrimaryTermin interfaceDocWriteRequest<IndexRequest>
-
ifSeqNo
public long ifSeqNo()If set, only perform this indexing 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<IndexRequest>
-
ifPrimaryTerm
public long ifPrimaryTerm()If set, only perform this indexing request if the document was last modification was assigned this primary term.If the document last modification was assigned a different term a
VersionConflictEngineExceptionwill be thrown.- Specified by:
ifPrimaryTermin interfaceDocWriteRequest<IndexRequest>
-
versionType
Description copied from interface:DocWriteRequestGet the document version type for this request- Specified by:
versionTypein interfaceDocWriteRequest<IndexRequest>- Returns:
- the document version type
-
preRoutingProcess
Description copied from interface:DocWriteRequestFinalize the request before routing it.- Specified by:
preRoutingProcessin interfaceDocWriteRequest<IndexRequest>
-
postRoutingProcess
Description copied from interface:DocWriteRequestFinalize the request after routing it.- Specified by:
postRoutingProcessin interfaceDocWriteRequest<IndexRequest>
-
autoGenerateId
public void autoGenerateId()Set the#id()to an automatically generated one and make this request compatible with the append-only optimization. -
autoGenerateTimeBasedId
public void autoGenerateTimeBasedId() -
autoGenerateTimeBasedId
Set the#id()to an automatically generated one, optimized for storage (compression) efficiency. If a routing hash is passed, it is included in the generated id starting at 9 bytes before the end.- Parameters:
hash- optional routing hash value, used to route requests by id to the right shard.
-
reset
public void reset()Resets thisIndexRequestclass, so that in case this instance can be used by the bulk/index action if it was already used before. For example if retrying a retryable failure. -
writeTo
Description copied from interface:WriteableWrite this into the StreamOutput.- Specified by:
writeToin interfaceWriteable- Overrides:
writeToin classReplicatedWriteRequest<IndexRequest>- Throws:
IOException
-
writeThin
Description copied from class:ReplicationRequestThin serialization that does not writeReplicationRequest.shardIdand will only writeReplicationRequest.indexif it is different from the index name inReplicationRequest.shardId.- Overrides:
writeThinin classReplicatedWriteRequest<IndexRequest>- Throws:
IOException
-
toString
- Specified by:
toStringin classReplicationRequest<IndexRequest>
-
includeDataStreams
public boolean includeDataStreams()Description copied from interface:IndicesRequestDetermines whether the request should be applied to data streams. Whenfalse, none of the names or wildcard expressions inIndicesRequest.indices()should be applied to or expanded to any data streams. All layers involved in the request's fulfillment including security, name resolution, etc., should respect this flag.- Specified by:
includeDataStreamsin interfaceIndicesRequest
-
isRetry
public boolean isRetry()Returnstrueif this request has been sent to a shard copy more than once. -
onRetry
public void onRetry()Description copied from class:ReplicationRequestThis method is called before this replication request is retried the first time.- Overrides:
onRetryin classReplicationRequest<IndexRequest>
-
getAutoGeneratedTimestamp
public long getAutoGeneratedTimestamp()Returns the timestamp the auto generated ID was created or -1L if the document has no auto generated timestamp. This method will return a positive value iff the id was auto generated. -
ramBytesUsed
public long ramBytesUsed()- Specified by:
ramBytesUsedin interfaceorg.apache.lucene.util.Accountable
-
isRequireAlias
public boolean isRequireAlias()Description copied from interface:DocWriteRequestShould this request override specifically require the destination to be an alias?- Specified by:
isRequireAliasin interfaceDocWriteRequest<IndexRequest>- Returns:
- boolean flag, when true specifically requires an alias
-
isRequireDataStream
public boolean isRequireDataStream()Description copied from interface:DocWriteRequestShould this request override specifically require the destination to be a data stream?- Specified by:
isRequireDataStreamin interfaceDocWriteRequest<IndexRequest>- Returns:
- boolean flag, when true specifically requires a data stream
-
setRequireDataStream
Set whether this IndexRequest requires a data stream. The data stream may be pre-existing or to-be-created. -
getIncludeSourceOnError
public boolean getIncludeSourceOnError() -
setIncludeSourceOnError
-
getConcreteWriteIndex
Description copied from interface:DocWriteRequestResolves the write index that should receive this request based on the provided index abstraction.- Specified by:
getConcreteWriteIndexin interfaceDocWriteRequest<IndexRequest>- Parameters:
ia- The provided index abstractionproject- The project metadata used to resolve the write index.- Returns:
- the write index that should receive this request
-
route
Description copied from interface:DocWriteRequestPick the appropriate shard id to receive this request.- Specified by:
routein interfaceDocWriteRequest<IndexRequest>
-
setRequireAlias
-
isWriteToFailureStore
public boolean isWriteToFailureStore()Returns a transient flag denoting that the local request should be routed to a failure store. Not persisted across the wire. N.B. If true, the failure store will be used regardless of whether the metadata indicates that the failure store is enabled. -
setWriteToFailureStore
Sets a transient flag denoting that the local request should be routed to a failure store. Not persisted across the wire. N.B. If true, the failure store will be used regardless of whether the metadata indicates that the failure store is enabled. It is the caller's responsibility to ensure that this is correct. -
setListExecutedPipelines
-
getListExecutedPipelines
public boolean getListExecutedPipelines() -
setDynamicTemplates
Specifies a map from the full path of field names to the name of dynamic mapping templates -
getDynamicTemplates
Returns a map from the full path of field names to the name of dynamic mapping templates.- See Also:
-
getRawTimestamp
-
setRawTimestamp
-
addPipeline
Adds the pipeline to the list of executed pipelines, if listExecutedPipelines is true- Parameters:
pipeline-
-
getExecutedPipelines
This returns the list of pipelines executed on the document for this request. If listExecutedPipelines is false, the response will be null, even if pipelines were executed. If listExecutedPipelines is true but no pipelines were executed, the list will be empty.- Returns:
-