[英]Create document id from two value fields separated by underscore using Elasticsearch Sink Connector for Kafka
I am trying to load records from a Kafka topic to Elasticsearch using the Elasticsearch Sink Connector, but I'm struggling to construct the document ids the way I would like them.我正在尝试使用 Elasticsearch 接收器连接器将来自 Kafka 主题的记录加载到 Elasticsearch,但我正在努力按照我想要的方式构建文档 ID。 I would like the document id that is written to Elasticsearch to be a composition of two values separated by underscore from my kafka topic's message.我希望写入 Elasticsearch 的文档 ID 是我的 kafka 主题消息中用下划线分隔的两个值的组合。
For example:例如:
My Kafka topic value has the following Avro schema:我的 Kafka 主题值具有以下 Avro 架构:
{
"type": "record",
"name": "SampleValue",
"namespace": "com.abc.test",
"fields": [
{
"name": "value1",
"type": [
"null",
{
"type": "int",
"java-class": "java.lang.Integer"
}
],
"default": null
},
{
"name": "value2",
"type": [
"null",
{
"type": "int",
"java-class": "java.lang.Integer"
}
],
"default": null
},
{
"name": "otherValue",
"type": [
"null",
{
"type": "int",
"java-class": "java.lang.Integer"
}
],
"default": null
}
]
}
I would like the document id that is written to Elasticsearch to be the combined values of value1 and value2 separated by an underscore.我希望写入 Elasticsearch 的文档 ID 是由下划线分隔的value1和value2的组合值。 If the given value in avro looked like如果 avro 中的给定值看起来像
{"value1": {"int": 123}, "value2": {"int": 456}, "value3": {"int": 0}}
then I would like the document id for Elasticsearch to be 123_456
.那么我希望123_456
的文档 ID 为 123_456 。
I can't figure out the correct way to chain transformations in my connector config to create a key that is composed of two values separated by an underscore.我无法找出在连接器配置中链接转换以创建由下划线分隔的两个值组成的键的正确方法。
I don't think there is a Single Message Transform out of the box that will do what you want.我认为没有开箱即用的单一消息转换可以满足您的需求。
You can either write your own, using the Transform API, or you can use a stream processor such as Kafka Streams or ksqlDB.您可以使用 Transform API 自己编写,也可以使用 stream 处理器,例如 Kafka Streams 或 ksqlDB。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.