use of org.apache.flink.connector.elasticsearch.sink.Elasticsearch7SinkBuilder in project flink by apache.
the class Elasticsearch7SinkExample method main.
public static void main(String[] args) throws Exception {
final ParameterTool parameterTool = ParameterTool.fromArgs(args);
if (parameterTool.getNumberOfParameters() < 3) {
System.out.println("Missing parameters!\n" + "Usage: --numRecords <numRecords> --index <index> --type <type>");
return;
}
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.enableCheckpointing(5000);
DataStream<String> source = env.fromSequence(0, parameterTool.getInt("numRecords") - 1).map((MapFunction<Long, String>) value -> "message #" + value);
source.sinkTo(new Elasticsearch7SinkBuilder<String>().setBulkFlushMaxActions(1).setHosts(new HttpHost("127.0.0.1", 9200, "http")).setEmitter((element, context, indexer) -> indexer.add(createIndexRequest(element, parameterTool))).build());
env.execute("Elasticsearch7.x end to end sink test example");
}
use of org.apache.flink.connector.elasticsearch.sink.Elasticsearch7SinkBuilder in project flink by apache.
the class Elasticsearch7SinkExample method main.
public static void main(String[] args) throws Exception {
final ParameterTool parameterTool = ParameterTool.fromArgs(args);
if (parameterTool.getNumberOfParameters() < 2) {
System.out.println("Missing parameters!\n" + "Usage: --numRecords <numRecords> --index <index>");
return;
}
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.enableCheckpointing(5000);
DataStream<Tuple2<String, String>> source = env.fromSequence(0, parameterTool.getInt("numRecords") - 1).flatMap(new FlatMapFunction<Long, Tuple2<String, String>>() {
@Override
public void flatMap(Long value, Collector<Tuple2<String, String>> out) {
final String key = String.valueOf(value);
final String message = "message #" + value;
out.collect(Tuple2.of(key, message + "update #1"));
out.collect(Tuple2.of(key, message + "update #2"));
}
});
ElasticsearchSink<Tuple2<String, String>> sink = new Elasticsearch7SinkBuilder<Tuple2<String, String>>().setHosts(new HttpHost("127.0.0.1", 9200, "http")).setEmitter((element, ctx, indexer) -> {
indexer.add(createIndexRequest(element.f1, parameterTool));
indexer.add(createUpdateRequest(element, parameterTool));
}).setBulkFlushMaxActions(// emit after every element, don't buffer
1).build();
source.sinkTo(sink);
env.execute("Elasticsearch 7.x end to end sink test example");
}
Aggregations