【问题标题】:Getting _jsonparsefailure with valid json in logstash在logstash中使用有效的json获取_jsonparsefailure
【发布时间】:2019-06-14 19:05:11
【问题描述】:

我目前正在尝试通过logstash 将json 发送到elasticsearch。但是,即使我已验证我的 json 格式正确,我仍然收到一个错误,即存在 jsonparsefailure。我的问题可能是什么?下面是我的配置文件和我的 json

input{
 file{
        path => "/Users/CFP668/Downloads/gs-accessing-data-mysql-master/complete/example.json"
        codec => json
        start_position => "beginning"
 }
}

filter{
    json{
        source => "message"
    }
}

output{
    elasticsearch{
        hosts => "localhost:9200"
        index => "test123" 
    }
    stdout { codec => rubydebug }
}
"{\"request_id\":1,\"requestDetail_id\":0,\"enrichedContent\":\"enrich cont example\",\"statusCode\":\"P\",\"reasonDesc\":\"This is a test\",\"createdBy\":\"Sarah\",\"createdDate\":\"Sep 24, 2010\"}"

【问题讨论】:

    标签: json logstash elastic-stack


    【解决方案1】:

    您的 json 对 Logstash 并不真正有效,您的键上的双引号之前有一个反斜杠,并且您的 json 对象也在双引号之间。

    您在源文件中的 json 行应该是这样的:

    {"request_id":1,"requestDetail_id":0,"enrichedContent":"enrich cont example","statusCode":"P","reasonDesc":"This is a test","createdBy":"Sarah","createdDate":"Sep 24, 2010"}
    

    在不更改生成方式的情况下使用当前 json 行的方法是在消息上使用 gsub 将 "{ 更改为 {}" 更改为 } 并删除反斜杠\

    以下过滤器管道可以做到这一点:

    filter {
        mutate {
            gsub => ["message","^\"{","{"]
            gsub => ["message","}\"$","}"]
            gsub => ["message","[\\]",""]
        }
        json {
            source => "message"
        }
    }
    

    您可以从输入块中删除codec => "json"

    【讨论】:

      猜你喜欢
      • 2016-01-27
      • 1970-01-01
      • 1970-01-01
      • 2019-01-14
      • 1970-01-01
      • 2018-08-30
      • 1970-01-01
      • 1970-01-01
      • 2020-12-16
      相关资源
      最近更新 更多