本文介绍了尝试使用Kafka Connect在Elasticsearch中为kafka主题编制索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将kafka中的主题以avro索引转换为elasticsearch格式,但是 我的时间戳记字段存在问题,无法识别 elasticsearch作为日期格式字段.

I want to index a topic from kafka in avro to elasticsearch format but I have problems with my timestamp field to be recognized by elasticsearch as date format field.

我对连接器使用了以下配置.

I have used the following configuration for the connector.

   {
          "name": "es-sink-barchart-10",
      "config": {
        "connector.class": "io.confluent.connect.elasticsearch.ElasticsearchSinkConnector",
        "value.converter": "io.confluent.connect.avro.AvroConverter",
        "key.converter": "io.confluent.connect.avro.AvroConverter",
        "key.converter.schema.registry.url": "http://localhost:8081",
        "value.converter.schema.registry.url": "http://localhost:8081",

        "connection.url": "http://localhost:9200",

        "type.name":"type.name=kafka-connect",

        "topics": "exchange_avro_01",

        "topic.index.map": "exchange_avro_01:exchange_barchart",

        "key.ignore": "true"
     }
    }

原始字段是bigint类型,我希望target字段是具有Elasticsearch的任何有效格式的日期类型.我定义了一个动态模板,尝试通过以下方式解决该问题:

The original field is bigint type and I want the target field to be date type with any valid format with elasticsearch. I have defined a dynamic template to try to solve it in the following way:

curl -XPUT "http://localhost:9200/_template/kafkaconnect/" -H 'Content-Type: application/json' -d'
{
  "index_patterns": "exchange*",
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  },
  "mappings": {
    "kafka-connect": {
      "dynamic_templates": [
    {
          "dates": {
        "match_mapping_type": "long",
            "match": "TIME",
            "mapping": {
              "type": "date",
          "format": "yyyy-MM-dd HH:mm:ss"
            }
          }
        }
      ]
     ,
      "properties": {
          "CLOSE": {
            "type": "double"
          },
         .
         .
         .
        }
      }

    }
  }
}'

当我加载上述连接器时,没有任何东西索引到elasticsearch.

When I load the connector described above nothing is indexed to elasticsearch.

有帮助吗?

推荐答案

如果您的来源是bigint,那么大概是一个时代.如果是一个纪元,那么它将不起作用:

If your source is a bigint then presumably it's an epoch. If it's an epoch, then this won't work:

"mapping": {
      "type": "date",
      "format": "yyyy-MM-dd HH:mm:ss"
        }

因为您要告诉Elasticsearch日期格式为yyyy-MM-dd HH:mm:ss(不是).

because you're telling Elasticsearch that the date format is yyyy-MM-dd HH:mm:ss (which it isn't).

因此,请尝试以下操作(暂时省略您的自定义映射;首先使它工作,然后再添加回去):

So instead, try this (omitting your custom mapping for the moment; get this working first and then add that back in):

{
  "index_patterns": "exchange*",
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  },
  "mappings": {
    "kafka-connect": {
      "dynamic_templates": [
        {
          "dates": {
            "match": "TIME",
            "mapping": {
              "type": "date"
            } } } ] } } }

也请参考: https://www.elastic.co/guide/zh-CN/elasticsearch/reference/current/dynamic-field-mapping.html#date-detection

检查Kafka Connect工作日志和Elasticsearch日志中是否有错误.

Check the Kafka Connect worker log and the Elasticsearch log for any errors.

这篇关于尝试使用Kafka Connect在Elasticsearch中为kafka主题编制索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 00:49