当前位置:   article > 正文

flink 写入到es_Flink学习(十一) Sink到Elasticsearch

flink json sink es示例

packagecom.wyh.streamingApi.sinkimportjava.utilimportorg.apache.flink.api.common.functions.RuntimeContextimportorg.apache.flink.streaming.api.scala._importorg.apache.flink.streaming.connectors.elasticsearch.{ElasticsearchSinkFunction, RequestIndexer}importorg.apache.flink.streaming.connectors.elasticsearch6.ElasticsearchSinkimportorg.apache.http.HttpHostimportorg.elasticsearch.client.Requests//温度传感器读数样例类

case classSensorReading(id: String, timestamp: Long, temperature: Double)

object Sink2ES {

def main(args: Array[String]): Unit={

val env=StreamExecutionEnvironment.getExecutionEnvironment

env.setParallelism(1)//Source操作

val inputStream = env.readTextFile("F:\\flink-study\\wyhFlinkSD\\data\\sensor.txt")//Transform操作

val dataStream: DataStream[SensorReading] = inputStream.map(data =>{

val dataArray= data.split(",")</

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/606470
推荐阅读
相关标签
  

闽ICP备14008679号