public class IndexRequest extends ReplicatedWriteRequest<IndexRequest> implements DocWriteRequest<IndexRequest>, CompositeIndicesRequest
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.TransportRequest.Empty
DocWriteRequest.OpType
IndicesRequest.Replaceable
WriteRequest.RefreshPolicy
Modifier and Type | Field and Description |
---|---|
static int |
UNSET_AUTO_GENERATED_TIMESTAMP
Value for
getAutoGeneratedTimestamp() if the document has an external
provided ID. |
DEFAULT_TIMEOUT, index, shardId, timeout, waitForActiveShards
Constructor and 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)
Constructs a new index request against the specific index and type.
|
IndexRequest(java.lang.String index,
java.lang.String type,
java.lang.String id)
Constructs a new index request against the index, type, id and using the source.
|
Modifier and Type | Method and Description |
---|---|
IndexRequest |
create(boolean create)
Set to true to force this index to use
OpType#CREATE . |
long |
getAutoGeneratedTimestamp()
Returns the timestamp the auto generated ID was created or -1 if the
document has no auto generated timestamp.
|
XContentType |
getContentType()
The content type.
|
java.lang.String |
getPipeline()
Returns the ingest pipeline to be executed before indexing the document
|
java.lang.String |
id()
The id of the indexed document.
|
IndexRequest |
id(java.lang.String id)
Sets the id of the indexed document.
|
boolean |
isRetry()
Returns
true 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 request
|
IndexRequest |
opType(DocWriteRequest.OpType opType)
Sets the type of operation to perform.
|
IndexRequest |
opType(java.lang.String opType)
Sets a string representation of the
#opType(OpType) . |
java.lang.String |
parent()
Get the parent for this request
|
IndexRequest |
parent(java.lang.String parent)
Sets the parent id of this document.
|
void |
process(MappingMetaData mappingMd,
boolean allowIdGeneration,
java.lang.String concreteIndex) |
void |
readFrom(StreamInput in)
Set this object's fields from a StreamInput.
|
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 |
setPipeline(java.lang.String pipeline)
Sets the ingest pipeline to be executed before indexing the document
|
BytesReference |
source()
The source of the document to index, recopied to a new array if it is unsafe.
|
IndexRequest |
source(byte[] source)
Deprecated.
|
IndexRequest |
source(byte[] source,
int offset,
int length)
Deprecated.
|
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(BytesReference source)
Deprecated.
|
IndexRequest |
source(BytesReference source,
XContentType xContentType)
Sets the document to index in bytes form.
|
IndexRequest |
source(java.util.Map source)
Index the Map in
Requests.INDEX_CONTENT_TYPE format |
IndexRequest |
source(java.util.Map source,
XContentType contentType)
Index the Map as the provided content type.
|
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)
Deprecated.
|
IndexRequest |
source(java.lang.String source,
XContentType xContentType)
Sets the document source to index.
|
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 |
timestamp()
Deprecated.
|
IndexRequest |
timestamp(java.lang.String timestamp)
Deprecated.
|
java.lang.String |
toString() |
TimeValue |
ttl()
Deprecated.
|
IndexRequest |
ttl(long ttl)
Deprecated.
|
IndexRequest |
ttl(java.lang.String ttl)
Deprecated.
|
IndexRequest |
ttl(TimeValue ttl)
Deprecated.
|
java.lang.String |
type()
The type of the indexed document.
|
IndexRequest |
type(java.lang.String type)
Sets the type of the indexed document.
|
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 request
|
IndexRequest |
versionType(VersionType versionType)
Sets the versioning type.
|
void |
writeTo(StreamOutput out)
Write this object's fields to a StreamOutput.
|
getRefreshPolicy, setRefreshPolicy
createTask, getDescription, index, index, indices, indicesOptions, setShardId, shardId, timeout, timeout, timeout, waitForActiveShards, waitForActiveShards, waitForActiveShards
getShouldStoreResult
getParentTask, setParentTask
remoteAddress, remoteAddress
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
index, indicesOptions, readDocumentRequest, writeDocumentRequest
indices
setRefreshPolicy
setParentTask
public static final int UNSET_AUTO_GENERATED_TIMESTAMP
getAutoGeneratedTimestamp()
if the document has an external
provided ID.public IndexRequest()
public IndexRequest(java.lang.String index)
type(String)
source(byte[], XContentType)
must be set.public IndexRequest(java.lang.String index, java.lang.String type)
source(byte[])
must be set.public IndexRequest(java.lang.String index, java.lang.String type, java.lang.String id)
index
- The index to index intotype
- The type to index intoid
- The id of documentpublic ActionRequestValidationException validate()
validate
in interface WriteRequest<IndexRequest>
validate
in class ReplicationRequest<IndexRequest>
public XContentType getContentType()
public java.lang.String type()
type
in interface DocWriteRequest<IndexRequest>
public IndexRequest type(java.lang.String type)
public java.lang.String id()
id
in interface DocWriteRequest<IndexRequest>
public IndexRequest id(java.lang.String id)
public IndexRequest routing(java.lang.String routing)
routing
in interface DocWriteRequest<IndexRequest>
public java.lang.String routing()
routing
in interface DocWriteRequest<IndexRequest>
public IndexRequest parent(java.lang.String parent)
public java.lang.String parent()
DocWriteRequest
parent
in interface DocWriteRequest<IndexRequest>
@Deprecated public IndexRequest timestamp(java.lang.String timestamp)
@Deprecated public java.lang.String timestamp()
@Deprecated public IndexRequest ttl(java.lang.String ttl)
@Deprecated public IndexRequest ttl(TimeValue ttl)
TimeValue
instance.@Deprecated public IndexRequest ttl(long ttl)
public IndexRequest setPipeline(java.lang.String pipeline)
public java.lang.String getPipeline()
public BytesReference source()
public java.util.Map<java.lang.String,java.lang.Object> sourceAsMap()
public IndexRequest source(java.util.Map source) throws ElasticsearchGenerationException
Requests.INDEX_CONTENT_TYPE
formatsource
- The map to indexElasticsearchGenerationException
public IndexRequest source(java.util.Map source, XContentType contentType) throws ElasticsearchGenerationException
source
- The map to indexElasticsearchGenerationException
@Deprecated public IndexRequest source(java.lang.String source)
source(String, XContentType)
public IndexRequest source(java.lang.String source, XContentType xContentType)
source(org.elasticsearch.common.xcontent.XContentBuilder)
or using the source(byte[], XContentType)
.public IndexRequest source(XContentBuilder sourceBuilder)
public IndexRequest source(java.lang.Object... source)
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.
public IndexRequest source(XContentType xContentType, java.lang.Object... source)
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.
@Deprecated public IndexRequest source(BytesReference source)
source(BytesReference, XContentType)
public IndexRequest source(BytesReference source, XContentType xContentType)
@Deprecated public IndexRequest source(byte[] source)
source(byte[], XContentType)
public IndexRequest source(byte[] source, XContentType xContentType)
@Deprecated public IndexRequest source(byte[] source, int offset, int length)
source(byte[], int, int, XContentType)
source
- The source to indexoffset
- The offset in the byte arraylength
- The length of the datapublic IndexRequest source(byte[] source, int offset, int length, XContentType xContentType)
source
- The source to indexoffset
- The offset in the byte arraylength
- The length of the datapublic IndexRequest opType(DocWriteRequest.OpType opType)
public IndexRequest opType(java.lang.String opType)
#opType(OpType)
. Can
be either "index" or "create".public IndexRequest create(boolean create)
OpType#CREATE
.public DocWriteRequest.OpType opType()
DocWriteRequest
opType
in interface DocWriteRequest<IndexRequest>
DocWriteRequest.OpType
public IndexRequest version(long version)
DocWriteRequest
version
in interface DocWriteRequest<IndexRequest>
public long version()
Versions.MATCH_ANY
and
opType is OpType#CREATE
, returns Versions.MATCH_DELETED
.version
in interface DocWriteRequest<IndexRequest>
public IndexRequest versionType(VersionType versionType)
DocWriteRequest
VersionType.INTERNAL
.versionType
in interface DocWriteRequest<IndexRequest>
public VersionType versionType()
DocWriteRequest
versionType
in interface DocWriteRequest<IndexRequest>
public void process(@Nullable MappingMetaData mappingMd, boolean allowIdGeneration, java.lang.String concreteIndex)
public void resolveRouting(MetaData metaData)
public void readFrom(StreamInput in) throws java.io.IOException
Streamable
readFrom
in interface Streamable
readFrom
in class ReplicatedWriteRequest<IndexRequest>
java.io.IOException
public void writeTo(StreamOutput out) throws java.io.IOException
Streamable
writeTo
in interface Streamable
writeTo
in class ReplicatedWriteRequest<IndexRequest>
java.io.IOException
public java.lang.String toString()
toString
in class ReplicationRequest<IndexRequest>
public boolean isRetry()
true
if this request has been sent to a shard copy more than once.public void onRetry()
ReplicationRequest
onRetry
in class ReplicationRequest<IndexRequest>
public long getAutoGeneratedTimestamp()