Class ElasticsearchSinkBase<T,C extends AutoCloseable>
- java.lang.Object
-
- org.apache.flink.api.common.functions.AbstractRichFunction
-
- org.apache.flink.streaming.api.functions.sink.RichSinkFunction<T>
-
- org.apache.flink.streaming.connectors.elasticsearch.ElasticsearchSinkBase<T,C>
-
- Type Parameters:
T- Type of the elements handled by this sinkC- Type of the Elasticsearch client, which implementsAutoCloseable
- 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.CheckpointedFunctionBase class for all Flink Elasticsearch Sinks.This class implements the common behaviour across Elasticsearch versions, such as the use of an internal
BulkProcessorto buffer multipleActionRequests before sending the requests to the cluster, as well as passing input records to the user providedElasticsearchSinkFunctionfor 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 ElasticsearchClient, handle failed item responses, etc.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classElasticsearchSinkBase.BulkFlushBackoffPolicyProvides a backoff policy for bulk requests.static classElasticsearchSinkBase.FlushBackoffTypeUsed to control whether the retry delay should increase exponentially or remain constant.
-
Field Summary
Fields Modifier and Type Field Description static StringCONFIG_KEY_BULK_FLUSH_BACKOFF_DELAYstatic StringCONFIG_KEY_BULK_FLUSH_BACKOFF_ENABLEstatic StringCONFIG_KEY_BULK_FLUSH_BACKOFF_RETRIESstatic StringCONFIG_KEY_BULK_FLUSH_BACKOFF_TYPEstatic StringCONFIG_KEY_BULK_FLUSH_INTERVAL_MSstatic StringCONFIG_KEY_BULK_FLUSH_MAX_ACTIONSstatic StringCONFIG_KEY_BULK_FLUSH_MAX_SIZE_MB
-
Constructor Summary
Constructors Constructor Description ElasticsearchSinkBase(ElasticsearchApiCallBridge<C> callBridge, Map<String,String> userConfig, ElasticsearchSinkFunction<T> elasticsearchSinkFunction, ActionRequestFailureHandler failureHandler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.elasticsearch.action.bulk.BulkProcessorbuildBulkProcessor(org.elasticsearch.action.bulk.BulkProcessor.Listener listener)Build theBulkProcessor.voidclose()voiddisableFlushOnCheckpoint()Disable flushing on checkpoint.voidinitializeState(org.apache.flink.runtime.state.FunctionInitializationContext context)voidinvoke(T value, org.apache.flink.streaming.api.functions.sink.SinkFunction.Context context)voidopen(org.apache.flink.configuration.Configuration parameters)voidsnapshotState(org.apache.flink.runtime.state.FunctionSnapshotContext context)-
Methods inherited from class org.apache.flink.api.common.functions.AbstractRichFunction
getIterationRuntimeContext, getRuntimeContext, setRuntimeContext
-
-
-
-
Field Detail
-
CONFIG_KEY_BULK_FLUSH_MAX_ACTIONS
public static final String CONFIG_KEY_BULK_FLUSH_MAX_ACTIONS
- See Also:
- Constant Field Values
-
CONFIG_KEY_BULK_FLUSH_MAX_SIZE_MB
public static final String CONFIG_KEY_BULK_FLUSH_MAX_SIZE_MB
- See Also:
- Constant Field Values
-
CONFIG_KEY_BULK_FLUSH_INTERVAL_MS
public static final String CONFIG_KEY_BULK_FLUSH_INTERVAL_MS
- See Also:
- Constant Field Values
-
CONFIG_KEY_BULK_FLUSH_BACKOFF_ENABLE
public static final String CONFIG_KEY_BULK_FLUSH_BACKOFF_ENABLE
- See Also:
- Constant Field Values
-
CONFIG_KEY_BULK_FLUSH_BACKOFF_TYPE
public static final String CONFIG_KEY_BULK_FLUSH_BACKOFF_TYPE
- See Also:
- Constant Field Values
-
CONFIG_KEY_BULK_FLUSH_BACKOFF_RETRIES
public static final String CONFIG_KEY_BULK_FLUSH_BACKOFF_RETRIES
- See Also:
- Constant Field Values
-
CONFIG_KEY_BULK_FLUSH_BACKOFF_DELAY
public static final String CONFIG_KEY_BULK_FLUSH_BACKOFF_DELAY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ElasticsearchSinkBase
public ElasticsearchSinkBase(ElasticsearchApiCallBridge<C> callBridge, Map<String,String> userConfig, ElasticsearchSinkFunction<T> elasticsearchSinkFunction, ActionRequestFailureHandler failureHandler)
-
-
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:
openin interfaceorg.apache.flink.api.common.functions.RichFunction- Overrides:
openin classorg.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
-
initializeState
public void initializeState(org.apache.flink.runtime.state.FunctionInitializationContext context) throws Exception- Specified by:
initializeStatein interfaceorg.apache.flink.streaming.api.checkpoint.CheckpointedFunction- Throws:
Exception
-
snapshotState
public void snapshotState(org.apache.flink.runtime.state.FunctionSnapshotContext context) throws Exception- Specified by:
snapshotStatein interfaceorg.apache.flink.streaming.api.checkpoint.CheckpointedFunction- Throws:
Exception
-
close
public void close() throws Exception- Specified by:
closein interfaceorg.apache.flink.api.common.functions.RichFunction- Overrides:
closein classorg.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 theBulkProcessor.Note: this is exposed for testing purposes.
-
-