简体   繁体   English

如何处理输入文件logstash中的特殊字符(“)

[英]how to handle special characters ( " ) in input file logstash

i'm having a problem with my data when push to ELK using logstash.使用 logstash 推送到 ELK 时,我的数据出现问题。 here is my input file这是我的输入文件

input {
        file {
                path => ["C:/Users/HoangHiep/Desktop/test17.txt"]
                type => "_doc"
                start_position => beginning
        }
}
filter {
    dissect {
        mapping => {
            "message" => "%{word}"
        }
    }
}
output {
        elasticsearch{
                hosts => ["localhost:9200"]
                index => "test01"
        }
        stdout { codec => rubydebug}
}

My data is我的数据是

"day la text"

this is the output这是输出

{
          "host" => "DESKTOP-T41GENH",
          "path" => "C:/Users/HoangHiep/Desktop/test17.txt",
    "@timestamp" => 2020-01-15T10:04:52.746Z,
      "@version" => "1",
          "type" => "_doc",
       "message" => "\"day la text\"\r",
          "word" => "\"day la text\"\r"
} 

Is there any way to handle the character ( " ). i want the "word" just be like "day la text \\r" don't have character \\"有没有办法处理字符(“)。我希望“单词”就像“day la text \\r”没有字符\\“

Thanks all.谢谢大家。

I can explain more about this if this change works for you.如果此更改适合您,我可以对此进行更多解释。 The reason I say is I have newest mac so I don't see the trailing \\r in my message.我说的原因是我有最新的 mac,所以我没有在我的消息中看到尾随的\\r

the input just like you have it "day la text"输入就像你有它"day la text"

    filter {
        mutate {
            gsub => [
                 "message","(\")", ""  
        ]   
        }   
}

response is回应是

{
    "@timestamp" => 2020-01-15T15:01:58.828Z,
      "@version" => "1",
       "headers" => {
           "http_version" => "HTTP/1.1",
         "request_method" => "POST",
            "http_accept" => "*/*",
        "accept_encoding" => "gzip, deflate",
          "postman_token" => "5ae8b2a0-2e94-433c-9ecc-e415731365b6",
          "cache_control" => "no-cache",
           "content_type" => "text/plain",
             "connection" => "keep-alive",
        "http_user_agent" => "PostmanRuntime/7.21.0",
              "http_host" => "localhost:8080",
         "content_length" => "13",
           "request_path" => "/"
    },
          "host" => "0:0:0:0:0:0:0:1",
        "message" => "day la text"   <===== see the extra inbuilt `\"` gone.
}

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

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