use of org.apache.flink.streaming.connectors.elasticsearch7.ElasticsearchSink in project Mastering-Distributed-Tracing by PacktPublishing.
the class ESSink method build.
public static ElasticsearchSink<TraceSummary> build() {
List<HttpHost> httpHosts = new ArrayList<>();
httpHosts.add(new HttpHost("127.0.0.1", 9200, "http"));
ElasticsearchSink.Builder<TraceSummary> esSinkBuilder = new ElasticsearchSink.Builder<>(httpHosts, new ElasticsearchSinkFunction<TraceSummary>() {
@Override
public void process(TraceSummary summary, RuntimeContext ctx, RequestIndexer indexer) {
indexer.add(//
Requests.indexRequest().index(//
"trace-summaries").type(//
"trace-summaries").id(//
summary.traceId).source(asJson(summary)));
}
});
// configuration for the bulk requests; this instructs the sink to emit after
// every element, otherwise they would be buffered
esSinkBuilder.setBulkFlushMaxActions(1);
return esSinkBuilder.build();
}
Aggregations