Class ElasticsearchSinkBase<T,​C extends AutoCloseable>

  • Type Parameters:
    T - Type of the elements handled by this sink
    C - Type of the Elasticsearch client, which implements AutoCloseable
    All Implemented Interfaces:
    Serializable, org.apache.flink.api.common.functions.Function, org.apache.flink.api.common.functions.RichFunction, org.apache.flink.streaming.api.checkpoint.CheckpointedFunction, org.apache.flink.streaming.api.functions.sink.SinkFunction<T>

    @Internal
    public abstract class ElasticsearchSinkBase<T,​C extends AutoCloseable>
    extends org.apache.flink.streaming.api.functions.sink.RichSinkFunction<T>
    implements org.apache.flink.streaming.api.checkpoint.CheckpointedFunction
    Base class for all Flink Elasticsearch Sinks.

    This class implements the common behaviour across Elasticsearch versions, such as the use of an internal BulkProcessor to buffer multiple ActionRequests before sending the requests to the cluster, as well as passing input records to the user provided ElasticsearchSinkFunction for processing.

    The version specific API calls for different Elasticsearch versions should be defined by a concrete implementation of a ElasticsearchApiCallBridge, which is provided to the constructor of this class. This call bridge is used, for example, to create a Elasticsearch Client, handle failed item responses, etc.

    See Also:
    Serialized Form
    • Method Detail

      • disableFlushOnCheckpoint

        public void disableFlushOnCheckpoint()
        Disable flushing on checkpoint. When disabled, the sink will not wait for all pending action requests to be acknowledged by Elasticsearch on checkpoints.

        NOTE: If flushing on checkpoint is disabled, the Flink Elasticsearch Sink does NOT provide any strong guarantees for at-least-once delivery of action requests.

      • open

        public void open​(org.apache.flink.configuration.Configuration parameters)
                  throws Exception
        Specified by:
        open in interface org.apache.flink.api.common.functions.RichFunction
        Overrides:
        open in class org.apache.flink.api.common.functions.AbstractRichFunction
        Throws:
        Exception
      • invoke

        public void invoke​(T value,
                           org.apache.flink.streaming.api.functions.sink.SinkFunction.Context context)
                    throws Exception
        Specified by:
        invoke in interface org.apache.flink.streaming.api.functions.sink.SinkFunction<T>
        Throws:
        Exception
      • initializeState

        public void initializeState​(org.apache.flink.runtime.state.FunctionInitializationContext context)
                             throws Exception
        Specified by:
        initializeState in interface org.apache.flink.streaming.api.checkpoint.CheckpointedFunction
        Throws:
        Exception
      • snapshotState

        public void snapshotState​(org.apache.flink.runtime.state.FunctionSnapshotContext context)
                           throws Exception
        Specified by:
        snapshotState in interface org.apache.flink.streaming.api.checkpoint.CheckpointedFunction
        Throws:
        Exception
      • close

        public void close()
                   throws Exception
        Specified by:
        close in interface org.apache.flink.api.common.functions.RichFunction
        Overrides:
        close in class org.apache.flink.api.common.functions.AbstractRichFunction
        Throws:
        Exception
      • buildBulkProcessor

        @VisibleForTesting
        protected org.elasticsearch.action.bulk.BulkProcessor buildBulkProcessor​(org.elasticsearch.action.bulk.BulkProcessor.Listener listener)
        Build the BulkProcessor.

        Note: this is exposed for testing purposes.