我正在连接Flink和Elastic Search。在documentation的帮助下。我使用Scala创建了一个接收器。
def getEsSink:ElasticsearchSink[CustomerSegementation] = {
val httpHosts = new util.ArrayList[HttpHost]
httpHosts.add(new HttpHost("10.0.35.148", 9200, "http"))
val esSinkBuilder = new ElasticsearchSink.Builder[CustomerSegementation](httpHosts, new ElasticsearchSinkFunction[CustomerSegementation]() {
def createIndexRequest(element: CustomerSegementation): IndexRequest = {
val json = new java.util.HashMap[String, String]
json.put("_id", element._id)
json.put("last_ordered_date", element.last_ordered_date.toString)
Requests.indexRequest.index("customerSegementation").`type`("test_type").source(json)
}
@Override
def process(element: CustomerSegementation, ctx: RuntimeContext, indexer: RequestIndexer): Unit = {
indexer.add(createIndexRequest(element))
}
})
esSinkBuilder.setBulkFlushMaxActions(1)
esSinkBuilder.build()
}
然后我正在尝试将接收器添加到流中
stream.addSink(getEsSink())
我不确定我到底要去哪里。我使用的是Flink版本1.6.0,ElasticSearch版本6和Scala版本2.11。
请帮助我。