Package org.elasticsearch.action.bulk
Class BulkProcessor
- java.lang.Object
-
- org.elasticsearch.action.bulk.BulkProcessor
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class BulkProcessor extends java.lang.Object implements java.io.Closeable
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
BulkProcessor.Builder
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BulkProcessor.Builder
A builder used to create a build an instance of a bulk processor.static interface
BulkProcessor.Listener
A listener for the execution.
-
Method Summary
Modifier and Type Method Description BulkProcessor
add(DeleteRequest request)
Adds anDeleteRequest
to the list of actions to execute.BulkProcessor
add(DocWriteRequest request)
Adds either a delete or an index request.BulkProcessor
add(DocWriteRequest request, java.lang.Object payload)
BulkProcessor
add(IndexRequest request)
Adds anIndexRequest
to the list of actions to execute.BulkProcessor
add(BytesReference data, java.lang.String defaultIndex, java.lang.String defaultType, java.lang.String defaultPipeline, java.lang.Object payload, XContentType xContentType)
Adds the data from the bytes to be processed by the bulk processorBulkProcessor
add(BytesReference data, java.lang.String defaultIndex, java.lang.String defaultType, XContentType xContentType)
Adds the data from the bytes to be processed by the bulk processorboolean
awaitClose(long timeout, java.util.concurrent.TimeUnit unit)
Closes the processor.static BulkProcessor.Builder
builder(java.util.function.BiConsumer<BulkRequest,ActionListener<BulkResponse>> consumer, BulkProcessor.Listener listener)
static BulkProcessor.Builder
builder(Client client, BulkProcessor.Listener listener)
void
close()
Closes the processor.protected void
ensureOpen()
void
flush()
Flush pending delete or index requests.
-
-
-
Method Detail
-
builder
public static BulkProcessor.Builder builder(Client client, BulkProcessor.Listener listener)
-
builder
public static BulkProcessor.Builder builder(java.util.function.BiConsumer<BulkRequest,ActionListener<BulkResponse>> consumer, BulkProcessor.Listener listener)
-
close
public void close()
Closes the processor. If flushing by time is enabled, then it's shutdown. Any remaining bulk actions are flushed.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
awaitClose
public boolean awaitClose(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
Closes the processor. If flushing by time is enabled, then it's shutdown. Any remaining bulk actions are flushed.If concurrent requests are not enabled, returns
true
immediately. If concurrent requests are enabled, waits for up to the specified timeout for all bulk requests to complete then returnstrue
If the specified waiting time elapses before all bulk requests complete,false
is returned.- Parameters:
timeout
- The maximum time to wait for the bulk requests to completeunit
- The time unit of thetimeout
argument- Returns:
true
if all bulk requests completed andfalse
if the waiting time elapsed before all the bulk requests completed- Throws:
java.lang.InterruptedException
- If the current thread is interrupted
-
add
public BulkProcessor add(IndexRequest request)
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).
-
add
public BulkProcessor add(DeleteRequest request)
Adds anDeleteRequest
to the list of actions to execute.
-
add
public BulkProcessor add(DocWriteRequest request)
Adds either a delete or an index request.
-
add
public BulkProcessor add(DocWriteRequest request, @Nullable java.lang.Object payload)
-
ensureOpen
protected void ensureOpen()
-
add
public BulkProcessor add(BytesReference data, @Nullable java.lang.String defaultIndex, @Nullable java.lang.String defaultType, XContentType xContentType) throws java.lang.Exception
Adds the data from the bytes to be processed by the bulk processor- Throws:
java.lang.Exception
-
add
public BulkProcessor add(BytesReference data, @Nullable java.lang.String defaultIndex, @Nullable java.lang.String defaultType, @Nullable java.lang.String defaultPipeline, @Nullable java.lang.Object payload, XContentType xContentType) throws java.lang.Exception
Adds the data from the bytes to be processed by the bulk processor- Throws:
java.lang.Exception
-
flush
public void flush()
Flush pending delete or index requests.
-
-