Class BulkProcessor2

java.lang.Object
org.elasticsearch.action.bulk.BulkProcessor2

public class BulkProcessor2 extends Object
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.

  • Method Details

    • builder

      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 events
      threadPool - The threadpool used to schedule the flush task for this bulk processor, if flushInterval is not null.
      Returns:
      the builder for BulkProcessor2
    • awaitClose

      public void awaitClose(long timeout, TimeUnit unit) throws InterruptedException
      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 complete
      unit - The time unit of the timeout argument
      Throws:
      InterruptedException - If the current thread is interrupted
    • add

      Adds an IndexRequest to the list of actions to execute. Follows the same behavior of IndexRequest (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 an DeleteRequest 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()