Package org.elasticsearch.action.bulk
Class BulkProcessor2
java.lang.Object
org.elasticsearch.action.bulk.BulkProcessor2
A bulk processor is a thread safe bulk processing class, allowing to easily set when to "flush" a new bulk request
(either based on number of actions, based on the size, or time), and to easily control the number of concurrent bulk
requests allowed to be executed in parallel.
In order to create a new bulk processor, use the BulkProcessor2.Builder
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A builder used to create a build an instance of a bulk processor.static interface
A listener for the execution. -
Method Summary
Modifier and TypeMethodDescriptionadd
(DeleteRequest request) Adds anDeleteRequest
to the list of actions to execute.add
(IndexRequest request) Adds anIndexRequest
to the list of actions to execute.void
awaitClose
(long timeout, TimeUnit unit) Closes the processor.static BulkProcessor2.Builder
builder
(BiConsumer<BulkRequest, ActionListener<BulkResponse>> consumer, BulkProcessor2.Listener listener, ThreadPool threadPool) protected void
-
Method Details
-
builder
public static BulkProcessor2.Builder builder(BiConsumer<BulkRequest, ActionListener<BulkResponse>> consumer, BulkProcessor2.Listener listener, ThreadPool threadPool) - Parameters:
consumer
- The consumer that is called to fulfil bulk operations. This consumer _must_ operate either very fast or asynchronously.listener
- The BulkProcessor2 listener that gets called on bulk eventsthreadPool
- The threadpool used to schedule the flush task for this bulk processor, if flushInterval is not null.- Returns:
- the builder for BulkProcessor2
-
awaitClose
Closes the processor. Any remaining bulk actions are flushed if they can be flushed in the given time.Waits for up to the specified timeout for all bulk requests to complete then returns
- Parameters:
timeout
- The maximum time to wait for the bulk requests to completeunit
- The time unit of thetimeout
argument- Throws:
InterruptedException
- If the current thread is interrupted
-
add
Adds anIndexRequest
to 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).- Throws:
EsRejectedExecutionException
- if adding the approximate size in bytes of the request to totalBytesInFlight would exceed maxBytesInFlight
-
add
Adds anDeleteRequest
to the list of actions to execute.- Throws:
EsRejectedExecutionException
- if adding the approximate size in bytes of the request to totalBytesInFlight would exceed maxBytesInFlight
-
ensureOpen
protected void ensureOpen()
-