【问题标题】:Indexing the logs into different types(schema) in elastic search based on matching patterns基于匹配模式在弹性搜索中将日志索引为不同类型(模式)
【发布时间】:2016-11-11 07:07:46
【问题描述】:

例如这里是我的日志文件

[2016-10-18 12:05:53.228] log example

[2016-10-18 11:55:53.228] 19249060-91df-11e6-be68-753fa0e2c729 logg example

[2016-10-18 11:35:53.228] 19249060-91ff-11e6-be68-753fa0e2c729 loggg example /api/userbasic/userinfo?requestedUserId=19249060-91df-11e6-be68-753fa0e2c729

我的日志的grok过滤器。这里我使用了多种模式

filter { 
    grok {
    match => [
        "message","\[%{TIMESTAMP_ISO8601:timestamp1}\] %{WORDS_EX:msg}",
        "message","\[%{TIMESTAMP_ISO8601:timestamp2}\] %{UUID:user_id1} %{WORDS_EX:msg2} %{URIPATHPARAM:path}",
        "message","\[%{TIMESTAMP_ISO8601:timestamp3}\] %{UUID:user_id2} %{WORDS_EX:msg3}"

    ]
}

} 

现在我想将日志索引到具有不同类型(架构)的弹性搜索中,例如 logstash/type1, logstash/type2, logstash/type3,

任何帮助表示赞赏!

【问题讨论】:

    标签: logstash logstash-grok


    【解决方案1】:

    首先,您的过滤器存在问题: grok 模式被逐一评估,当一个模式匹配时,其他模式将不会被评估,因此需要从最具体的模式(带有 @ 的模式987654322@) 到最一般的(带有%{WORDS_EX:msg} 的那个)像这样:

    "message","\[%{TIMESTAMP_ISO8601:timestamp2}\] %{UUID:user_id1} %{WORDS_EX:msg2} %{URIPATHPARAM:path}",
    "message","\[%{TIMESTAMP_ISO8601:timestamp3}\] %{UUID:user_id2} %{WORDS_EX:msg3}",
    "message","\[%{TIMESTAMP_ISO8601:timestamp1}\] %{WORDS_EX:msg}"
    

    然后你可以像这样使用conditionnals的各个字段的存在/不存在:

    if [path] {
        elasticsearch {
            ...
        }
    } else if [user_id2] {
        elasticsearch {
            ...
        }
    } else {
        elasticsearch {
            ...
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-03-12
      • 1970-01-01
      • 2016-01-06
      • 2017-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-20
      • 1970-01-01
      相关资源
      最近更新 更多