Class BulkProcessor

org.elasticsearch.action.bulk.BulkProcessor
All Implemented Interfaces:
,

public class BulkProcessor extends implements
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.

  • Method Details

    • builder

      public static BulkProcessor.Builder builder(Client client, BulkProcessor.Listener listener, Scheduler flushScheduler, Scheduler retryScheduler,  onClose)
      Parameters:
      client - The client that executes the bulk operations
      listener - The BulkProcessor listener that gets called on bulk events
      flushScheduler - The scheduler that is used to flush
      retryScheduler - The scheduler that is used for retries
      onClose - The runnable instance that is executed on close. Consumers are required to clean up the schedulers.
      Returns:
      the builder for BulkProcessor
    • builder

      public static BulkProcessor.Builder builder(Client client, BulkProcessor.Listener listener)
      Parameters:
      client - The client that executes the bulk operations
      listener - The BulkProcessor listener that gets called on bulk events
      Returns:
      the builder for BulkProcessor
    • builder

      public static <BulkRequest,​ActionListener<BulkResponse>> consumer, BulkProcessor.Listener listener)
      Deprecated.
      Parameters:
      consumer - The consumer that is called to fulfil bulk operations
      listener - The BulkProcessor listener that gets called on bulk events
      Returns:
      the builder for BulkProcessor
    • builder

      public static <BulkRequest,​ActionListener<BulkResponse>> consumer, BulkProcessor.Listener listener,  name)
      Parameters:
      consumer - The consumer that is called to fulfil bulk operations
      listener - The BulkProcessor listener that gets called on bulk events
      name - The name of this processor, e.g. to identify the scheduler threads
      Returns:
      the builder for BulkProcessor
    • 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:
       in interface 
      Specified by:
       in interface 
    • awaitClose

      public boolean awaitClose(long timeout,  unit) throws
      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 returns true 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 complete
      unit - The time unit of the timeout argument
      Returns:
      true if all bulk requests completed and false if the waiting time elapsed before all the bulk requests completed
      Throws:
      - If the current thread is interrupted
    • add

      public BulkProcessor add(IndexRequest request)
      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).
    • add

      public BulkProcessor add(DeleteRequest request)
      Adds an DeleteRequest to the list of actions to execute.
    • add

      public BulkProcessor add(DocWriteRequest<?> request)
      Adds either a delete or an index request.
    • ensureOpen

      protected void ensureOpen()
    • add

      public BulkProcessor add(BytesReference data, @Nullable  defaultIndex, @Nullable  defaultType, org.elasticsearch.common.xcontent.XContentType xContentType) throws
      Adds the data from the bytes to be processed by the bulk processor
      Throws:
    • add

      public BulkProcessor add(BytesReference data, @Nullable  defaultIndex, @Nullable  defaultType, @Nullable  defaultPipeline, org.elasticsearch.common.xcontent.XContentType xContentType) throws
      Adds the data from the bytes to be processed by the bulk processor
      Throws:
    • flush

      public void flush()
      Flush pending delete or index requests.