Package org.elasticsearch.action.index
Class IndexRequest
java.lang.Object
- All Implemented Interfaces:
CompositeIndicesRequest
,DocWriteRequest<IndexRequest>
,IndicesRequest
,WriteRequest<IndexRequest>
,Writeable
,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.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.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 Modifier and Type Field Description static long
UNSET_AUTO_GENERATED_TIMESTAMP
Value forgetAutoGeneratedTimestamp()
if the document has an external provided ID.Fields inherited from class org.elasticsearch.action.support.replication.ReplicationRequest
DEFAULT_TIMEOUT, index, shardId, timeout, waitForActiveShards
-
Constructor Summary
Constructors Constructor Description IndexRequest()
IndexRequest(java.lang.String index)
Constructs a new index request against the specific index.IndexRequest(java.lang.String index, java.lang.String type)
Deprecated.Types are in the process of being removed.IndexRequest(java.lang.String index, java.lang.String type, java.lang.String id)
Deprecated.Types are in the process of being removed.IndexRequest(StreamInput in)
-
Method Summary
Modifier and Type Method Description void
checkAutoIdWithOpTypeCreateSupportedByVersion(Version version)
IndexRequest
create(boolean create)
Set totrue
to force this index to useDocWriteRequest.OpType.CREATE
.IndexRequest
defaultTypeIfNull(java.lang.String defaultType)
Deprecated.Types are in the process of being removed.long
getAutoGeneratedTimestamp()
Returns the timestamp the auto generated ID was created or -1L if the document has no auto generated timestamp.XContentType
getContentType()
The content type.java.lang.String
getFinalPipeline()
Returns the final ingest pipeline to be executed before indexing the document.java.lang.String
getPipeline()
Returns the ingest pipeline to be executed before indexing the documentjava.lang.String
id()
The id of the indexed document.IndexRequest
id(java.lang.String id)
Sets the id of the indexed document.long
ifPrimaryTerm()
If set, only perform this indexing request if the document was last modification was assigned this primary term.long
ifSeqNo()
If set, only perform this indexing request if the document was last modification was assigned this sequence number.boolean
isPipelineResolved()
Returns whether or not the pipeline for this request has been resolved by the coordinating node.IndexRequest
isPipelineResolved(boolean isPipelineResolved)
Sets if the pipeline for this request has been resolved by the coordinating node.boolean
isRetry()
Returnstrue
if this request has been sent to a shard copy more than once.void
onRetry()
This method is called before this replication request is retried the first time.DocWriteRequest.OpType
opType()
Get the requested document operation type of the requestIndexRequest
opType(java.lang.String opType)
Sets a string representation of theopType(OpType)
.IndexRequest
opType(DocWriteRequest.OpType opType)
Sets the type of operation to perform.void
process(Version indexCreatedVersion, MappingMetaData mappingMd, java.lang.String concreteIndex)
void
resolveRouting(MetaData metaData)
java.lang.String
routing()
Controls the shard routing of the request.IndexRequest
routing(java.lang.String routing)
Controls the shard routing of the request.IndexRequest
setFinalPipeline(java.lang.String finalPipeline)
Sets the final ingest pipeline to be executed before indexing the document.IndexRequest
setIfPrimaryTerm(long term)
only performs this indexing request if the document was last modification was assigned the given primary term.IndexRequest
setIfSeqNo(long seqNo)
only perform this indexing request if the document was last modification was assigned the given sequence number.IndexRequest
setPipeline(java.lang.String pipeline)
Sets the ingest pipeline to be executed before indexing the documentBytesReference
source()
The source of the document to index, recopied to a new array if it is unsafe.IndexRequest
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).IndexRequest
source(byte[] source, XContentType xContentType)
Sets the document to index in bytes form.IndexRequest
source(java.lang.Object... source)
Sets the content source to index using the default content type (Requests.INDEX_CONTENT_TYPE
)IndexRequest
source(java.lang.String source, XContentType xContentType)
Sets the document source to index.IndexRequest
source(java.util.Map<java.lang.String,?> source)
Index the Map inRequests.INDEX_CONTENT_TYPE
formatIndexRequest
source(java.util.Map<java.lang.String,?> source, XContentType contentType)
Index the Map as the provided content type.IndexRequest
source(BytesReference source, XContentType xContentType)
Sets the document to index in bytes form.IndexRequest
source(XContentBuilder sourceBuilder)
Sets the content source to index.IndexRequest
source(XContentType xContentType, java.lang.Object... source)
Sets the content source to index.java.util.Map<java.lang.String,java.lang.Object>
sourceAsMap()
java.lang.String
toString()
java.lang.String
type()
Deprecated.Types are in the process of being removed.IndexRequest
type(java.lang.String type)
Deprecated.Types are in the process of being removed.ActionRequestValidationException
validate()
long
version()
Returns stored version.IndexRequest
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.VersionType
versionType()
Get the document version type for this requestIndexRequest
versionType(VersionType versionType)
Sets the versioning type.void
writeTo(StreamOutput out)
Write this into the StreamOutput.Methods inherited from class org.elasticsearch.action.support.replication.ReplicatedWriteRequest
getRefreshPolicy, setRefreshPolicy
Methods inherited from class org.elasticsearch.action.support.replication.ReplicationRequest
createTask, getDescription, index, index, indices, indicesOptions, routedBasedOnClusterVersion, shardId, timeout, timeout, timeout, waitForActiveShards, waitForActiveShards, waitForActiveShards
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
-
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:
java.io.IOException
-
IndexRequest
public IndexRequest() -
IndexRequest
public IndexRequest(java.lang.String index)Constructs a new index request against the specific index. Thetype(String)
source(byte[], XContentType)
must be set. -
IndexRequest
@Deprecated public IndexRequest(java.lang.String index, java.lang.String type)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 public IndexRequest(java.lang.String index, java.lang.String type, java.lang.String id)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:
validate
in interfaceWriteRequest<IndexRequest>
- Overrides:
validate
in 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 -
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 interfaceDocWriteRequest<IndexRequest>
- Returns:
- the type
-
type
Deprecated.Types are in the process of being removed.Sets the type of the indexed document.- Specified by:
type
in 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:
defaultTypeIfNull
in interfaceDocWriteRequest<IndexRequest>
- Returns:
- the Request
-
id
public java.lang.String id()The id of the indexed document. If not set, will be automatically generated.- Specified by:
id
in 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:
routing
in interfaceDocWriteRequest<IndexRequest>
- 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 interfaceDocWriteRequest<IndexRequest>
- Returns:
- the Routing
-
setPipeline
Sets the ingest pipeline to be executed before indexing the document -
getPipeline
public java.lang.String 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
public java.lang.String 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
public java.util.Map<java.lang.String,java.lang.Object> sourceAsMap() -
source
public IndexRequest source(java.util.Map<java.lang.String,?> source) throws ElasticsearchGenerationExceptionIndex the Map inRequests.INDEX_CONTENT_TYPE
format- Parameters:
source
- The map to index- Throws:
ElasticsearchGenerationException
-
source
public IndexRequest source(java.util.Map<java.lang.String,?> source, XContentType contentType) throws ElasticsearchGenerationExceptionIndex the Map as the provided content type.- Parameters:
source
- The map to index- Throws:
ElasticsearchGenerationException
-
source
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
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
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 totrue
to force this index to useDocWriteRequest.OpType.CREATE
. -
opType
Description copied from interface:DocWriteRequest
Get the requested document operation type of the request- Specified by:
opType
in interfaceDocWriteRequest<IndexRequest>
- Returns:
- the operation type
DocWriteRequest.OpType
-
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 interfaceDocWriteRequest<IndexRequest>
-
version
public long version()Returns stored version. If currently stored version isVersions.MATCH_ANY
and opType isDocWriteRequest.OpType.CREATE
, returnsVersions.MATCH_DELETED
.- Specified by:
version
in interfaceDocWriteRequest<IndexRequest>
- Returns:
- the document version
-
versionType
Description copied from interface:DocWriteRequest
Sets the versioning type. Defaults toVersionType.INTERNAL
.- Specified by:
versionType
in 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 aVersionConflictEngineException
will be thrown.- Specified by:
setIfSeqNo
in 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 aVersionConflictEngineException
will be thrown.- Specified by:
setIfPrimaryTerm
in 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 aVersionConflictEngineException
will be thrown.- Specified by:
ifSeqNo
in 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 aVersionConflictEngineException
will be thrown.- Specified by:
ifPrimaryTerm
in interfaceDocWriteRequest<IndexRequest>
-
versionType
Description copied from interface:DocWriteRequest
Get the document version type for this request- Specified by:
versionType
in interfaceDocWriteRequest<IndexRequest>
- Returns:
- the document version type
-
process
public void process(Version indexCreatedVersion, @Nullable MappingMetaData mappingMd, java.lang.String concreteIndex) -
resolveRouting
-
checkAutoIdWithOpTypeCreateSupportedByVersion
-
writeTo
Description copied from interface:Writeable
Write this into the StreamOutput.- Specified by:
writeTo
in interfaceWriteable
- Overrides:
writeTo
in classReplicatedWriteRequest<IndexRequest>
- Throws:
java.io.IOException
-
toString
public java.lang.String toString()- Specified by:
toString
in classReplicationRequest<IndexRequest>
-
isRetry
public boolean isRetry()Returnstrue
if this request has been sent to a shard copy more than once. -
onRetry
public void onRetry()Description copied from class:ReplicationRequest
This method is called before this replication request is retried the first time.- Overrides:
onRetry
in 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.
-