【问题标题】:how to handle special characters ( " ) in input file logstash如何处理输入文件logstash中的特殊字符(“)
【发布时间】:2020-05-02 03:01:20
【问题描述】:

在使用 logstash 推送到 ELK 时,我的数据出现问题。 这是我的输入文件

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}
}

我的数据是

"day la text"

这是输出

{
          "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"
} 

有没有办法处理字符( " )。 我希望“单词”就像“day la text \r”没有字符\“

谢谢大家。

【问题讨论】:

    标签: elasticsearch logstash elk


    【解决方案1】:

    如果此更改对您有用,我可以对此进行更多解释。我说的原因是我有最新的 mac,所以我在消息中看不到结尾的 \r

    输入就像你有它"day la text"

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

    回复是

    {
        "@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.
    }
    

    【讨论】:

    • 我确实喜欢你的建议,但它不起作用。实际上,我想处理引号。因为 kibana 的输出有“”。我的数据示例,在 kibana 将显示是。词:“天拉文”。我只想要文本 => day la text.
    • 好吧,我以为你只需要删除最后一个引号。让我修改代码以删除第一个引号
    • 查看我对gsub 块所做的更改。我删除了$,不仅选择了结尾\",而且都选择了
    猜你喜欢
    • 2022-07-21
    • 1970-01-01
    • 2010-10-30
    • 2010-11-19
    • 2016-02-25
    • 2022-01-21
    • 2013-01-22
    • 2013-08-22
    相关资源
    最近更新 更多