汇编Kafka连接ElasticSearch ID文档创建

时间:2018-04-13 12:31:21

标签: elasticsearch apache-kafka apache-kafka-connect

我使用kafka connect elasticsearch连接器将主题中的数据写入ElasticSearch索引。主题消息的键和值都是json格式。由于以下错误,连接器无法启动:

    org.apache.kafka.connect.errors.DataException: MAP is not supported as the document id.

以下是我的消息格式(键|值):

    {"key":"OKOK","start":1517241690000,"end":1517241695000}     |   {"measurement":"responses","count":9,"sum":1350.0,"max":150.0,"min":150.0,"avg":150.0} 

以下是我用来创建连接器的POST请求的正文:

{
 "name": "elasticsearch-sink-connector",
 "config": {
 "connector.class":"io.confluent.connect.elasticsearch.ElasticsearchSinkConnector",
 "tasks.max": "1",
 "topics": "output-topic-elastic",
 "connection.url": "http://elasticsearch:9200",
 "type.name": "aggregator",
 "schemas.enable": "false",
 "topic.schema.ignore": "true",
 "topic.key.ignore": "false",
 "value.converter": "org.apache.kafka.connect.json.JsonConverter",
 "value.converter.schemas.enable": "false", 
 "key.converter": "org.apache.kafka.connect.json.JsonConverter",
 "key.converter.schemas.enable": "false", 
 "key.ignore":"false",
 "topic.index.map": "output-topic-elastic:aggregator",
 "name": "elasticsearch-sink",
 "transforms": "InsertKey",
"transforms.InsertKey.type":"org.apache.kafka.connect.transforms.ValueToKey",
"transforms.InsertKey.fields":"key"
}}

任何帮助都会非常感激。我在stackoverflow 1上发现了一个类似的问题,但我对这些答案没有运气。

ES document ID creation

1 个答案:

答案 0 :(得分:0)

您还需要ExtractField

"transforms": "InsertKey,extractKey",
"transforms.InsertKey.type":"org.apache.kafka.connect.transforms.ValueToKey",
"transforms.InsertKey.fields":"key",
"transforms.extractKey.type":"org.apache.kafka.connect.transforms.ExtractField$Key",
"transforms.extractKey.field":"key"

查看this post了解详情。