Package org.elasticsearch.action.bulk
Class BulkRequest
- java.lang.Object
-
- org.elasticsearch.transport.TransportMessage
-
- org.elasticsearch.transport.TransportRequest
-
- org.elasticsearch.action.ActionRequest
-
- org.elasticsearch.action.bulk.BulkRequest
-
- All Implemented Interfaces:
CompositeIndicesRequest,WriteRequest<BulkRequest>,Streamable,Writeable,TaskAwareRequest
public class BulkRequest extends ActionRequest implements CompositeIndicesRequest, WriteRequest<BulkRequest>
A bulk request holds an orderedIndexRequests,DeleteRequests andUpdateRequests and allows to executes it in a single batch. Note that we only support refresh on the bulk request not per item.- See Also:
Client.bulk(BulkRequest)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.elasticsearch.transport.TransportRequest
TransportRequest.Empty
-
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
-
-
Constructor Summary
Constructors Constructor Description BulkRequest()BulkRequest(java.lang.String globalIndex, java.lang.String globalType)
-
Method Summary
Modifier and Type Method Description BulkRequestadd(byte[] data, int from, int length, java.lang.String defaultIndex, java.lang.String defaultType, XContentType xContentType)Adds a framed data in binary formatBulkRequestadd(byte[] data, int from, int length, XContentType xContentType)Adds a framed data in binary formatBulkRequestadd(java.lang.Iterable<DocWriteRequest<?>> requests)Adds a list of requests to be executed.BulkRequestadd(DeleteRequest request)Adds anDeleteRequestto the list of actions to execute.BulkRequestadd(DeleteRequest request, java.lang.Object payload)BulkRequestadd(DocWriteRequest<?> request)BulkRequestadd(DocWriteRequest<?>... requests)Adds a list of requests to be executed.BulkRequestadd(DocWriteRequest<?> request, java.lang.Object payload)Add a request to the current BulkRequest.BulkRequestadd(IndexRequest request)Adds anIndexRequestto the list of actions to execute.BulkRequestadd(IndexRequest request, java.lang.Object payload)BulkRequestadd(UpdateRequest request)Adds anUpdateRequestto the list of actions to execute.BulkRequestadd(UpdateRequest request, java.lang.Object payload)BulkRequestadd(BytesReference data, java.lang.String defaultIndex, java.lang.String defaultType, boolean allowExplicitIndex, XContentType xContentType)Adds a framed data in binary formatBulkRequestadd(BytesReference data, java.lang.String defaultIndex, java.lang.String defaultType, java.lang.String defaultRouting, java.lang.String[] defaultFields, FetchSourceContext defaultFetchSourceContext, java.lang.String defaultPipeline, java.lang.Object payload, boolean allowExplicitIndex, XContentType xContentType)BulkRequestadd(BytesReference data, java.lang.String defaultIndex, java.lang.String defaultType, XContentType xContentType)Adds a framed data in binary formatlongestimatedSizeInBytes()The estimated size in bytes of the bulk request.java.lang.StringgetDescription()Returns optional description of the request to be displayed by the task managerWriteRequest.RefreshPolicygetRefreshPolicy()Should this request trigger a refresh (WriteRequest.RefreshPolicy.IMMEDIATE), wait for a refresh ( WriteRequest.RefreshPolicy.WAIT_UNTIL), or proceed ignore refreshes entirely (WriteRequest.RefreshPolicy.NONE, the default).intnumberOfActions()The number of actions in the bulk request.java.util.List<java.lang.Object>payloads()The list of optional payloads associated with requests in the same order as the requests.java.lang.Stringpipeline()BulkRequestpipeline(java.lang.String globalPipeline)voidreadFrom(StreamInput in)Set this object's fields from a StreamInput.java.util.List<DocWriteRequest<?>>requests()The list of requests in this bulk request.java.lang.Stringrouting()BulkRequestrouting(java.lang.String globalRouting)BulkRequestsetRefreshPolicy(WriteRequest.RefreshPolicy refreshPolicy)Should this request trigger a refresh (WriteRequest.RefreshPolicy.IMMEDIATE), wait for a refresh ( WriteRequest.RefreshPolicy.WAIT_UNTIL), or proceed ignore refreshes entirely (WriteRequest.RefreshPolicy.NONE, the default).TimeValuetimeout()BulkRequesttimeout(java.lang.String timeout)A timeout to wait if the index operation can't be performed immediately.BulkRequesttimeout(TimeValue timeout)A timeout to wait if the index operation can't be performed immediately.ActionRequestValidationExceptionvalidate()ActiveShardCountwaitForActiveShards()BulkRequestwaitForActiveShards(int waitForActiveShards)A shortcut forwaitForActiveShards(ActiveShardCount)where the numerical shard count is passed in, instead of having to first callActiveShardCount.from(int)to get the ActiveShardCount.BulkRequestwaitForActiveShards(ActiveShardCount waitForActiveShards)Sets the number of shard copies that must be active before proceeding with the write.voidwriteTo(StreamOutput out)Write this object's fields to a StreamOutput.-
Methods inherited from class org.elasticsearch.action.ActionRequest
getShouldStoreResult
-
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, toString, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.tasks.TaskAwareRequest
createTask, setParentTask
-
Methods inherited from interface org.elasticsearch.action.support.WriteRequest
setRefreshPolicy
-
-
-
-
Field Detail
-
timeout
protected TimeValue timeout
-
-
Method Detail
-
add
public BulkRequest add(DocWriteRequest<?>... requests)
Adds a list of requests to be executed. Either index or delete requests.
-
add
public BulkRequest add(DocWriteRequest<?> request)
-
add
public BulkRequest add(DocWriteRequest<?> request, @Nullable java.lang.Object payload)
Add a request to the current BulkRequest.- Parameters:
request- Request to addpayload- Optional payload- Returns:
- the current bulk request
-
add
public BulkRequest add(java.lang.Iterable<DocWriteRequest<?>> requests)
Adds a list of requests to be executed. Either index or delete requests.
-
add
public BulkRequest add(IndexRequest request)
Adds anIndexRequestto the list of actions to execute. Follows the same behavior ofIndexRequest(for example, if no id is provided, one will be generated, or usage of the create flag).
-
add
public BulkRequest add(IndexRequest request, @Nullable java.lang.Object payload)
-
add
public BulkRequest add(UpdateRequest request)
Adds anUpdateRequestto the list of actions to execute.
-
add
public BulkRequest add(UpdateRequest request, @Nullable java.lang.Object payload)
-
add
public BulkRequest add(DeleteRequest request)
Adds anDeleteRequestto the list of actions to execute.
-
add
public BulkRequest add(DeleteRequest request, @Nullable java.lang.Object payload)
-
requests
public java.util.List<DocWriteRequest<?>> requests()
The list of requests in this bulk request.
-
payloads
@Nullable public java.util.List<java.lang.Object> payloads()
The list of optional payloads associated with requests in the same order as the requests. Note, elements within it might be null if no payload has been provided.Note, if no payloads have been provided, this method will return null (as to conserve memory overhead).
-
numberOfActions
public int numberOfActions()
The number of actions in the bulk request.
-
estimatedSizeInBytes
public long estimatedSizeInBytes()
The estimated size in bytes of the bulk request.
-
add
public BulkRequest add(byte[] data, int from, int length, XContentType xContentType) throws java.io.IOException
Adds a framed data in binary format- Throws:
java.io.IOException
-
add
public BulkRequest add(byte[] data, int from, int length, @Nullable java.lang.String defaultIndex, @Nullable java.lang.String defaultType, XContentType xContentType) throws java.io.IOException
Adds a framed data in binary format- Throws:
java.io.IOException
-
add
public BulkRequest add(BytesReference data, @Nullable java.lang.String defaultIndex, @Nullable java.lang.String defaultType, XContentType xContentType) throws java.io.IOException
Adds a framed data in binary format- Throws:
java.io.IOException
-
add
public BulkRequest add(BytesReference data, @Nullable java.lang.String defaultIndex, @Nullable java.lang.String defaultType, boolean allowExplicitIndex, XContentType xContentType) throws java.io.IOException
Adds a framed data in binary format- Throws:
java.io.IOException
-
add
public BulkRequest add(BytesReference data, @Nullable java.lang.String defaultIndex, @Nullable java.lang.String defaultType, @Nullable java.lang.String defaultRouting, @Nullable java.lang.String[] defaultFields, @Nullable FetchSourceContext defaultFetchSourceContext, @Nullable java.lang.String defaultPipeline, @Nullable java.lang.Object payload, boolean allowExplicitIndex, XContentType xContentType) throws java.io.IOException
- Throws:
java.io.IOException
-
waitForActiveShards
public BulkRequest waitForActiveShards(ActiveShardCount waitForActiveShards)
Sets the number of shard copies that must be active before proceeding with the write. SeeReplicationRequest.waitForActiveShards(ActiveShardCount)for details.
-
waitForActiveShards
public BulkRequest waitForActiveShards(int waitForActiveShards)
A shortcut forwaitForActiveShards(ActiveShardCount)where the numerical shard count is passed in, instead of having to first callActiveShardCount.from(int)to get the ActiveShardCount.
-
waitForActiveShards
public ActiveShardCount waitForActiveShards()
-
setRefreshPolicy
public BulkRequest setRefreshPolicy(WriteRequest.RefreshPolicy refreshPolicy)
Description copied from interface:WriteRequestShould this request trigger a refresh (WriteRequest.RefreshPolicy.IMMEDIATE), wait for a refresh ( WriteRequest.RefreshPolicy.WAIT_UNTIL), or proceed ignore refreshes entirely (WriteRequest.RefreshPolicy.NONE, the default).- Specified by:
setRefreshPolicyin interfaceWriteRequest<BulkRequest>
-
getRefreshPolicy
public WriteRequest.RefreshPolicy getRefreshPolicy()
Description copied from interface:WriteRequestShould this request trigger a refresh (WriteRequest.RefreshPolicy.IMMEDIATE), wait for a refresh ( WriteRequest.RefreshPolicy.WAIT_UNTIL), or proceed ignore refreshes entirely (WriteRequest.RefreshPolicy.NONE, the default).- Specified by:
getRefreshPolicyin interfaceWriteRequest<BulkRequest>
-
timeout
public final BulkRequest timeout(TimeValue timeout)
A timeout to wait if the index operation can't be performed immediately. Defaults to1m.
-
pipeline
public final BulkRequest pipeline(java.lang.String globalPipeline)
-
routing
public final BulkRequest routing(java.lang.String globalRouting)
-
timeout
public final BulkRequest timeout(java.lang.String timeout)
A timeout to wait if the index operation can't be performed immediately. Defaults to1m.
-
timeout
public TimeValue timeout()
-
pipeline
public java.lang.String pipeline()
-
routing
public java.lang.String routing()
-
validate
public ActionRequestValidationException validate()
- Specified by:
validatein interfaceWriteRequest<BulkRequest>- Specified by:
validatein classActionRequest
-
readFrom
public void readFrom(StreamInput in) throws java.io.IOException
Description copied from interface:StreamableSet this object's fields from a StreamInput.- Specified by:
readFromin interfaceStreamable- Overrides:
readFromin classActionRequest- Throws:
java.io.IOException
-
writeTo
public void writeTo(StreamOutput out) throws java.io.IOException
Description copied from interface:StreamableWrite this object's fields to a StreamOutput.- Specified by:
writeToin interfaceStreamable- Specified by:
writeToin interfaceWriteable- Overrides:
writeToin classActionRequest- Throws:
java.io.IOException
-
getDescription
public java.lang.String getDescription()
Description copied from interface:TaskAwareRequestReturns optional description of the request to be displayed by the task manager- Specified by:
getDescriptionin interfaceTaskAwareRequest
-
-