Package org.elasticsearch.action.index
Class IndexRequest
- All Implemented Interfaces:
org.apache.lucene.util.Accountable,CompositeIndicesRequest,DocWriteRequest<IndexRequest>,IndicesRequest,WriteRequest<IndexRequest>,Writeable,org.elasticsearch.core.RefCounted,TaskAwareRequest
public class IndexRequest
extends ReplicatedWriteRequest<IndexRequest>
implements DocWriteRequest<IndexRequest>, CompositeIndicesRequest
Index request to index a typed JSON document into a specific index and make it searchable. Best
created using
Requests.indexRequest(String).
The index requires the ReplicationRequest.index(), type(String), 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.common.xcontent.XContentBuilder)).
If the id(String) is not set, it will be automatically generated.-
Nested Class Summary
Nested classes/interfaces inherited from class org.elasticsearch.transport.TransportRequest
TransportRequest.EmptyNested classes/interfaces inherited from interface org.elasticsearch.action.DocWriteRequest
DocWriteRequest.OpTypeNested classes/interfaces inherited from interface org.elasticsearch.action.IndicesRequest
IndicesRequest.ReplaceableNested 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 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
REQUIRE_ALIAS -
Constructor Summary
ConstructorsConstructorDescriptionIndexRequest(String index)Constructs a new index request against the specific index.IndexRequest(String index, String type)Deprecated.Types are in the process of being removed.IndexRequest(String index, String type, String id)Deprecated.Types are in the process of being removed.IndexRequest(ShardId shardId, StreamInput in) -
Method Summary
Modifier and TypeMethodDescriptionvoidcreate(boolean create)Set totrueto force this index to useDocWriteRequest.OpType.CREATE.defaultTypeIfNull(String defaultType)Deprecated.Types are in the process of being removed.longReturns the timestamp the auto generated ID was created or -1L if the document has no auto generated timestamp.org.elasticsearch.common.xcontent.XContentTypeThe content type.Returns a map from the full path of field names to the name of dynamic mapping templates.Returns the final ingest pipeline to be executed before indexing the document.Returns the ingest pipeline to be executed before indexing the documentid()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.Returns the indices options used to resolve indices.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?booleanisRetry()Returnstrueif this request has been sent to a shard copy more than once.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.voidprocess(Version indexCreatedVersion, MappingMetadata mappingMd, String concreteIndex)longvoidresolveRouting(Metadata metadata)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.setPipeline(String pipeline)Sets the ingest pipeline to be executed before indexing the documentsetRequireAlias(boolean requireAlias)source()The source of the document to index, recopied to a new array if it is unsafe.source(byte[] source, int offset, int length, org.elasticsearch.common.xcontent.XContentType xContentType)Sets the document to index in bytes form (assumed to be safe to be used from different threads).source(byte[] source, org.elasticsearch.common.xcontent.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)Sets the document source to index.Index the Map inRequests.INDEX_CONTENT_TYPEformatIndex the Map as the provided content type.source(BytesReference source, org.elasticsearch.common.xcontent.XContentType xContentType)Sets the document to index in bytes form.source(org.elasticsearch.common.xcontent.XContentBuilder sourceBuilder)Sets the content source to index.Sets the content source to index.toString()type()Deprecated.Types are in the process of being removed.Deprecated.Types are in the process of being removed.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, routedBasedOnClusterVersion, shardId, timeout, timeout, timeout, waitForActiveShards, waitForActiveShards, waitForActiveShardsMethods inherited from class org.elasticsearch.action.ActionRequest
getShouldStoreResultMethods inherited from class org.elasticsearch.transport.TransportRequest
getParentTask, setParentTaskMethods inherited from class org.elasticsearch.transport.TransportMessage
decRef, incRef, remoteAddress, remoteAddress, 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, indexMethods inherited from interface org.elasticsearch.action.IndicesRequest
allowsRemoteIndices, indicesMethods inherited from interface org.elasticsearch.tasks.TaskAwareRequest
setParentTaskMethods inherited from interface org.elasticsearch.action.support.WriteRequest
setRefreshPolicy
-
Field Details
-
UNSET_AUTO_GENERATED_TIMESTAMP
public static final long UNSET_AUTO_GENERATED_TIMESTAMPValue forgetAutoGeneratedTimestamp()if the document has an external provided ID.- See Also:
- Constant Field Values
-
-
Constructor Details
-
IndexRequest
- Throws:
IOException
-
IndexRequest
- Throws:
IOException
-
IndexRequest
public IndexRequest() -
IndexRequest
Constructs a new index request against the specific index. Thetype(String)source(byte[], XContentType)must be set. -
IndexRequest
Deprecated.Types are in the process of being removed. UseIndexRequest(String)instead.Constructs a new index request against the specific index and type. Thesource(byte[], XContentType)must be set. -
IndexRequest
Deprecated.Types are in the process of being removed. UseIndexRequest(String)withid(String)instead.Constructs a new index request against the index, type, id and using the source.- Parameters:
index- The index to index intotype- The type to index intoid- The id of document
-
-
Method Details
-
validate
- Specified by:
validatein interfaceWriteRequest<IndexRequest>- Overrides:
validatein classReplicationRequest<IndexRequest>
-
indicesOptions
Description copied from interface:IndicesRequestReturns the indices options used to resolve indices. They tell for instance whether a single index is accepted, whether an empty array will be converted to _all, and how wildcards will be expanded if needed.- Specified by:
indicesOptionsin interfaceDocWriteRequest<IndexRequest>- Specified by:
indicesOptionsin interfaceIndicesRequest- Overrides:
indicesOptionsin classReplicationRequest<IndexRequest>- Returns:
- the indices options
-
getContentType
public org.elasticsearch.common.xcontent.XContentType 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 -
type
Deprecated.Types are in the process of being removed.The type of the indexed document.- Specified by:
typein interfaceDocWriteRequest<IndexRequest>- Returns:
- the type
-
type
Deprecated.Types are in the process of being removed.Sets the type of the indexed document.- Specified by:
typein interfaceDocWriteRequest<IndexRequest>- Returns:
- the Request
-
defaultTypeIfNull
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:
defaultTypeIfNullin interfaceDocWriteRequest<IndexRequest>- Returns:
- the Request
-
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
-
source
Index the Map inRequests.INDEX_CONTENT_TYPEformat- Parameters:
source- The map to index- Throws:
ElasticsearchGenerationException
-
source
public IndexRequest source(Map<String,?> source, org.elasticsearch.common.xcontent.XContentType contentType) throws ElasticsearchGenerationExceptionIndex the Map as the provided content type.- Parameters:
source- The map to index- Throws:
ElasticsearchGenerationException
-
source
public IndexRequest source(String source, org.elasticsearch.common.xcontent.XContentType xContentType)Sets the document source to index. Note, its preferable to either set it usingsource(org.elasticsearch.common.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
public IndexRequest source(org.elasticsearch.common.xcontent.XContentType xContentType, Object... 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.
-
source
public IndexRequest source(BytesReference source, org.elasticsearch.common.xcontent.XContentType xContentType)Sets the document to index in bytes form. -
source
public IndexRequest source(byte[] source, org.elasticsearch.common.xcontent.XContentType xContentType)Sets the document to index in bytes form. -
source
public IndexRequest source(byte[] source, int offset, int length, org.elasticsearch.common.xcontent.XContentType xContentType)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 aVersionConflictEngineExceptionwill 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 aVersionConflictEngineExceptionwill 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 aVersionConflictEngineExceptionwill 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
-
process
public void process(Version indexCreatedVersion, @Nullable MappingMetadata mappingMd, String concreteIndex) -
resolveRouting
-
checkAutoIdWithOpTypeCreateSupportedByVersion
-
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
-
setRequireAlias
-
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:
setDynamicTemplates(Map)
-