Package org.elasticsearch.action.index
Class IndexRequestBuilder
- java.lang.Object
-
- org.elasticsearch.action.ActionRequestBuilder<Request,Response,RequestBuilder>
-
- org.elasticsearch.action.support.replication.ReplicationRequestBuilder<IndexRequest,IndexResponse,IndexRequestBuilder>
-
- org.elasticsearch.action.index.IndexRequestBuilder
-
- All Implemented Interfaces:
WriteRequestBuilder<IndexRequestBuilder>
public class IndexRequestBuilder extends ReplicationRequestBuilder<IndexRequest,IndexResponse,IndexRequestBuilder> implements WriteRequestBuilder<IndexRequestBuilder>
An index document action request builder.
-
-
Field Summary
-
Fields inherited from class org.elasticsearch.action.ActionRequestBuilder
action, client, request
-
-
Constructor Summary
Constructors Constructor Description IndexRequestBuilder(ElasticsearchClient client, IndexAction action)
IndexRequestBuilder(ElasticsearchClient client, IndexAction action, java.lang.String index)
-
Method Summary
Modifier and Type Method Description IndexRequestBuilder
setCreate(boolean create)
Set totrue
to force this index to useDocWriteRequest.OpType.CREATE
.IndexRequestBuilder
setId(java.lang.String id)
Sets the id to index the document under.IndexRequestBuilder
setIfPrimaryTerm(long term)
only perform this indexing request if the document was last modification was assigned the given primary term.IndexRequestBuilder
setIfSeqNo(long seqNo)
only perform this indexing request if the document was last modification was assigned the given sequence number.IndexRequestBuilder
setOpType(DocWriteRequest.OpType opType)
Sets the type of operation to perform.IndexRequestBuilder
setParent(java.lang.String parent)
Sets the parent id of this document.IndexRequestBuilder
setPipeline(java.lang.String pipeline)
Sets the ingest pipeline to be executed before indexing the documentIndexRequestBuilder
setRouting(java.lang.String routing)
Controls the shard routing of the request.IndexRequestBuilder
setSource(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).IndexRequestBuilder
setSource(byte[] source, XContentType xContentType)
Sets the document to index in bytes form.IndexRequestBuilder
setSource(java.lang.Object... source)
Constructs a simple document with a field name and value pairs.IndexRequestBuilder
setSource(java.lang.String source, XContentType xContentType)
Sets the document source to index.IndexRequestBuilder
setSource(java.util.Map<java.lang.String,?> source)
Index the Map as a JSON.IndexRequestBuilder
setSource(java.util.Map<java.lang.String,?> source, XContentType contentType)
Index the Map as the provided content type.IndexRequestBuilder
setSource(BytesReference source, XContentType xContentType)
Sets the source.IndexRequestBuilder
setSource(XContentBuilder sourceBuilder)
Sets the content source to index.IndexRequestBuilder
setSource(XContentType xContentType, java.lang.Object... source)
Constructs a simple document with a field name and value pairs.IndexRequestBuilder
setType(java.lang.String type)
Sets the type to index the document to.IndexRequestBuilder
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.IndexRequestBuilder
setVersionType(VersionType versionType)
Sets the versioning type.-
Methods inherited from class org.elasticsearch.action.support.replication.ReplicationRequestBuilder
setIndex, setTimeout, setTimeout, setWaitForActiveShards, setWaitForActiveShards
-
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
-
IndexRequestBuilder
public IndexRequestBuilder(ElasticsearchClient client, IndexAction action)
-
IndexRequestBuilder
public IndexRequestBuilder(ElasticsearchClient client, IndexAction action, @Nullable java.lang.String index)
-
-
Method Detail
-
setType
public IndexRequestBuilder setType(java.lang.String type)
Sets the type to index the document to.
-
setId
public IndexRequestBuilder setId(java.lang.String id)
Sets the id to index the document under. Optional, and if not set, one will be automatically generated.
-
setRouting
public IndexRequestBuilder 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 IndexRequestBuilder setParent(java.lang.String parent)
Sets the parent id of this document. If routing is not set, automatically set it as the routing as well.
-
setSource
public IndexRequestBuilder setSource(BytesReference source, XContentType xContentType)
Sets the source.
-
setSource
public IndexRequestBuilder setSource(java.util.Map<java.lang.String,?> source)
Index the Map as a JSON.- Parameters:
source
- The map to index
-
setSource
public IndexRequestBuilder setSource(java.util.Map<java.lang.String,?> source, XContentType contentType)
Index the Map as the provided content type.- Parameters:
source
- The map to index
-
setSource
public IndexRequestBuilder setSource(java.lang.String source, XContentType xContentType)
Sets the document source to index.Note, its preferable to either set it using
setSource(org.elasticsearch.common.xcontent.XContentBuilder)
or using thesetSource(byte[], XContentType)
.
-
setSource
public IndexRequestBuilder setSource(XContentBuilder sourceBuilder)
Sets the content source to index.
-
setSource
public IndexRequestBuilder setSource(byte[] source, XContentType xContentType)
Sets the document to index in bytes form.
-
setSource
public IndexRequestBuilder setSource(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).- Parameters:
source
- The source to indexoffset
- The offset in the byte arraylength
- The length of the dataxContentType
- The type/format of the source
-
setSource
public IndexRequestBuilder setSource(java.lang.Object... source)
Constructs a simple document with a field name and value pairs.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.
-
setSource
public IndexRequestBuilder setSource(XContentType xContentType, java.lang.Object... source)
Constructs a simple document with a field name and value pairs.Note: the number of objects passed as varargs to this method must be an even number. Also the first argument in each pair (the field name) must have a valid String representation.
-
setOpType
public IndexRequestBuilder setOpType(DocWriteRequest.OpType opType)
Sets the type of operation to perform.
-
setCreate
public IndexRequestBuilder setCreate(boolean create)
Set totrue
to force this index to useDocWriteRequest.OpType.CREATE
.
-
setVersion
public IndexRequestBuilder 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 IndexRequestBuilder setVersionType(VersionType versionType)
Sets the versioning type. Defaults toVersionType.INTERNAL
.
-
setIfSeqNo
public IndexRequestBuilder setIfSeqNo(long seqNo)
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.
-
setIfPrimaryTerm
public IndexRequestBuilder setIfPrimaryTerm(long term)
only perform 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.
-
setPipeline
public IndexRequestBuilder setPipeline(java.lang.String pipeline)
Sets the ingest pipeline to be executed before indexing the document
-
-