简体   繁体   English

logstash传输数据到elasticsearch解析日期错误

[英]logstash transfer data to elasticsearch Parsing date error

this is my Mysql.config这是我的 Mysql.config

input {
    stdin {
    }
    jdbc {

    jdbc_connection_string => "jdbc:mysql://localhost:3306/xc_course?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC"
    # the user we wish to excute our statement as
    jdbc_user => "root"
    jdbc_password => "1234"
    # the path to our downloaded jdbc driver
    jdbc_driver_library =>"/usr/local/elasticsearch/logstash/mysql-connector-java-5.1.4.jar"
    # the name of the driver class for mysql
    jdbc_driver_class => "com.mysql.jdbc.Driver"
    jdbc_paging_enabled => "true"
    jdbc_page_size => "50000"
    #statement_filepath => "/conf/course.sql"
    statement => "select * from course_pub where timestamp > date_add(:sql_last_value,INTERVAL 8 HOUR)"
    schedule => "* * * * *"

    record_last_run => true

    last_run_metadata_path => "/usr/local/elasticsearch/elasticsearch-6.2.1/config/logstash_metadata"   

    }
}
output {
    elasticsearch {
    hosts => "localhost:9200"
    #hosts => ["localhost:9200","localhost:9202","localhost:9203"]
    index => "xc_course"
    document_id => "%{id}"
    document_type => "doc"
    template =>"/usr/local/elasticsearch/logstash-6.2.1/config/xc_course_template.json"
    template_name =>"xc_course"
    template_overwrite =>"true"

    }
    stdout {

        codec => json_lines

    }
}

this is my template.json这是我的 template.json

{
    "mappings": {
        "doc": {
            "properties": { 
                "charge": {
                    "type": "keyword"
                },
                "description": {
                    "analyzer": "ik_max_word",
                    "search_analyzer": "ik_smart",
                    "type": "text"
                },
                "end_time": {
                    "format": "yyyy‐MM‐dd HH:mm:ss",
                    "type": "date"
                },
                "expires": {
                    "format": "yyyy‐MM‐dd HH:mm:ss",
                    "type": "date"
                },
                "grade": {
                    "type": "keyword"
                },
                "id": {
                    "type": "keyword"
                },
                "mt": {
                    "type": "keyword"
                },
                "name": {
                    "analyzer": "ik_max_word",
                    "search_analyzer": "ik_smart",
                    "type": "text"
                },
                "pic": {
                    "index": false,
                    "type": "keyword"
                },
                "price": {
                    "type": "float"
                },
                "price_old": {
                    "type": "float"
                },
                "pub_time": {
                    "format": "yyyy‐MM‐dd HH:mm:ss",
                    "type": "date"
                },
                "qq": {
                    "index": false,
                    "type": "keyword"
                },
                "st": {
                    "type": "keyword"
                },
                "start_time": {
                    "format": "yyyy‐MM‐dd HH:mm:ss",
                    "type": "date"
                },
                "status": {
                    "type": "keyword"
                },
                "studymodel": {
                    "type": "keyword"
                },
                "teachmode": {
                    "type": "keyword"
                },
                "teachplan": {
                    "analyzer": "ik_max_word",
                    "search_analyzer": "ik_smart",
                    "type": "text"
                },
                "users": {
                    "index": false,
                    "type": "text"
                },
                "valid": {
                    "type": "keyword"
                }
            }
        }
    },
    "template": "xc_course"
}

this is my elasticSearch index_mapping这是我的 elasticSearch index_mapping

    {
        "properties": {
            "description": {
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_smart",
                "type": "text"
            },
            "grade": {
                "type": "keyword"
            },
            "id": {
                "type": "keyword"
            },
            "mt": {
                "type": "keyword"
            },
            "name": {
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_smart",
                "type": "text"
            },
            "users": {
                "index": false,
                "type": "text"
            },
            "charge": {
                "type": "keyword"
            },
            "valid": {
                "type": "keyword"
            },
            "pic": {
                "index": false,
                "type": "keyword"
            },
            "qq": {
                "index": false,
                "type": "keyword"
            },
            "price": {
                "type": "float"
            },
            "price_old": {
                "type": "float"
            },
            "st": {
                "type": "keyword"
            },
            "status": {
                "type": "keyword"
            },
            "studymodel": {
                "type": "keyword"
            },
            "teachmode": {
                "type": "keyword"
            },
            "teachplan": {
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_smart",
                "type": "text"
            },
            "expires": {
                "type": "date",
                "format": "yyyy‐MM‐dd HH:mm:ss"
            },
            "pub_time": {
                "type": "date",
                "format": "yyyy‐MM‐dd HH:mm:ss"
            },
            "start_time": {
                "type": "date",
                "format": "yyyy‐MM‐dd HH:mm:ss"
            },
            "end_time": {
                "type": "date",
                "format": "yyyy‐MM‐dd HH:mm:ss"
            }
        }
    }

but when it start但是当它开始时

Could not index event to Elasticsearch.无法将事件索引到 Elasticsearch。 {:status=>400, :action=>["index", {:_id=>"4028e58161bd3b380161bd3bcd2f0000", :_index=>"xc_course", :_type=>"doc", :_routing=>nil}, #LogStash::Event:0x62e0a8f9], :response=>{"index"=>{"_index"=>"xc_course", "_type"=>"doc", "_id"=>"4028e58161bd3b380161bd3bcd2f0000", "status"=>400, "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse [start_time]", "caused_by"=>{"type"=>"illegal_argument_exception", "reason"=>"Invalid format: \\"2019-12-20T15:18:13.000Z\\" is malformed at \\"-12-20T15:18:13.000Z\\""}}}}} {:status=>400, :action=>["index", {:_id=>"4028e58161bd3b380161bd3bcd2f0000", :_index=>"xc_course", :_type=>"doc", :_routing=>nil}, #LogStash ::Event:0x62e0a8f9], :response=>{"index"=>{"_index"=>"xc_course", "_type"=>"doc", "_id"=>"4028e58161bd3b380161bd3bcd2f0000", "status"=> 400, "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"未能解析 [start_time]", "caused_by"=>{"type"=>"illegal_argument_exception", "reason"= >"无效格式:\\"2019-12-20T15:18:13.000Z\\"在\\"-12-20T15:18:13.000Z\\""}}}}}处格式错误

failed to parse [start_time]", "caused_by"=>{"type"=>"illegal_argument_exception"无法解析 [start_time]", "caused_by"=>{"type"=>"illegal_argument_exception"

** "Invalid format: \\"2019-12-20T15:18:13.000Z\\" is malformed at \\"-12-20T15:18:13.000Z\\""** ** "无效格式:\\"2019-12-20T15:18:13.000Z\\" 格式错误,位于 \\"-12-20T15:18:13.000Z\\""**

but inmy data base my data type is this 2019-12-28 19:24:41但是在我的数据库中我的数据类型是这个2019-12-28 19:24:41

when i make date to null ,its worke ,but like 2019-12-28 19:24:41 would Parsing error当我将日期设为 null 时,它会起作用,但是像 2019-12-28 19:24:41 会解析错误

so how to deal it那么如何处理呢

The jdbc input will automatically change date columns to LogStash::Timestamp type, but your index template expects them to be text. jdbc 输入会自动将日期列更改为 LogStash::Timestamp 类型,但您的索引模板希望它们是文本。 Remove the "format" from the date fields in your index template.从索引模板的日期字段中删除“格式”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM