Class ElasticsearchSink<T>
- java.lang.Object
-
- org.apache.flink.api.common.functions.AbstractRichFunction
-
- org.apache.flink.streaming.api.functions.sink.RichSinkFunction<T>
-
- com.mtfelisb.flink.connectors.elasticsearch.sink.ElasticsearchSink<T>
-
- Type Parameters:
T-
- 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>
public class ElasticsearchSink<T> extends org.apache.flink.streaming.api.functions.sink.RichSinkFunction<T> implements org.apache.flink.streaming.api.checkpoint.CheckpointedFunctionElasticsearchSink A RichSinkFunction with CheckpointedFunction implemented; The ElasticsearchSink uses BulkRequest internally to each incoming event and flushes if a specified threshold is reached, or if the checkpoint is enabled, when the snapshot is triggered.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ElasticsearchSink(INetworkConfigFactory networkConfigFactory, Emitter<T> emitter, Long threshold, IBulkRequestFactory bulkRequestFactory)ElasticsearchSink
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()close the close method when triggered by Flink will destroy the ElasticsearchClient connectionvoidinitializeState(org.apache.flink.runtime.state.FunctionInitializationContext functionInitializationContext)initializeStatevoidinvoke(T value, org.apache.flink.streaming.api.functions.sink.SinkFunction.Context context)invoke buffers every data element in the stream until the threshold is reachedvoidopen(org.apache.flink.configuration.Configuration parameters)open creates the connection with the Elasticsearch cluster relying on the provided factoryvoidsnapshotState(org.apache.flink.runtime.state.FunctionSnapshotContext functionSnapshotContext)snapshotState used as a hook; that means every checkpoint will trigger a bulk request to Elasticsearch-
Methods inherited from class org.apache.flink.api.common.functions.AbstractRichFunction
getIterationRuntimeContext, getRuntimeContext, setRuntimeContext
-
-
-
-
Constructor Detail
-
ElasticsearchSink
public ElasticsearchSink(INetworkConfigFactory networkConfigFactory, Emitter<T> emitter, Long threshold, IBulkRequestFactory bulkRequestFactory)
ElasticsearchSink- Parameters:
networkConfigFactory- a factory to create the network conn with Elasticsearchemitter- user defined operations to be sent in bulk requeststhreshold- used defined limiting the bulk request size
-
-
Method Detail
-
open
public void open(org.apache.flink.configuration.Configuration parameters) throws Exceptionopen creates the connection with the Elasticsearch cluster relying on the provided factory- Specified by:
openin interfaceorg.apache.flink.api.common.functions.RichFunction- Overrides:
openin classorg.apache.flink.api.common.functions.AbstractRichFunction- Parameters:
parameters- The configuration containing the parameters attached to the contract.- Throws:
Exception
-
invoke
public void invoke(T value, org.apache.flink.streaming.api.functions.sink.SinkFunction.Context context) throws Exception
invoke buffers every data element in the stream until the threshold is reached
-
snapshotState
public void snapshotState(org.apache.flink.runtime.state.FunctionSnapshotContext functionSnapshotContext) throws ExceptionsnapshotState used as a hook; that means every checkpoint will trigger a bulk request to Elasticsearch- Specified by:
snapshotStatein interfaceorg.apache.flink.streaming.api.checkpoint.CheckpointedFunction- Parameters:
functionSnapshotContext- the context for drawing a snapshot of the operator- Throws:
Exception
-
initializeState
public void initializeState(org.apache.flink.runtime.state.FunctionInitializationContext functionInitializationContext) throws ExceptioninitializeState- Specified by:
initializeStatein interfaceorg.apache.flink.streaming.api.checkpoint.CheckpointedFunction- Parameters:
functionInitializationContext- the context for initializing the operator- Throws:
Exception
-
close
public void close() throws Exceptionclose the close method when triggered by Flink will destroy the ElasticsearchClient connection- Specified by:
closein interfaceorg.apache.flink.api.common.functions.RichFunction- Overrides:
closein classorg.apache.flink.api.common.functions.AbstractRichFunction- Throws:
Exception
-
-