logstash强制不添加可在索引名中使用的值

logstash强制不添加可在索引名中使用的值,logstash,Logstash,我有以下用于日志存储的过滤器: filter { mutate { # Sets the default value for application, in case someone forgot to set it in their # Gelf configuration

我有以下用于日志存储的过滤器:

filter {
  mutate {
    # Sets the default value for application, in case someone forgot to set it in their                                                                    
    # Gelf configuration                                                                                                                                   
    coerce => { "application" => "unknown_application" }
  }
}
我的期望是,如果我没有名为“application”的字段,它应该添加该字段,并命名为“unknown\u application”

以下是我的输出:

output {
  # (Un)comment for debugging purposes                                                                                                                     
  stdout { codec => rubydebug }
  elasticsearch {
        hosts => ["http://localhost:9200/"]
        index => "app-%{application}-%{+YYYY.MM.dd}"
  }
}
我希望,如果我在没有应用程序的情况下记录某个内容,它应该会卡在elasticsearch中的app-unknown_application-(date)索引中。当我添加一条“应用程序”字段中没有任何内容的消息时,我会将我的项目固定在一个名为以下内容的集合中:

app-%{application}-2020.09.30

很明显,强制措施出了问题——它似乎什么也没做。知道我做错了什么吗

完整的日志存储配置文件如下所示:

input {
  gelf {
    id => "gelf"
    use_udp => false
    use_tcp => true
  }
}

filter {
  json {
    source => "message"
    target => "json_message"
  }
  prune {
   blacklist_names => [ "source_host", "facility" ]
  }
  mutate {
    # Sets the default value for application, in case someone forgot to set it in their                                                                    
    # Gelf configuration                                                                                                                                   
    coerce => { "application" => "unknown_application" }
  }
}

output {
  # (Un)comment for debugging purposes                                                                                                                     
  stdout { codec => rubydebug }
  elasticsearch {
        hosts => ["http://localhost:9200/"]
        index => "app-%{application}-%{+YYYY.MM.dd}"
  }
}
我的期望是,如果我没有一个名为“application”的字段,那么 应该添加该字段

否,强制修改已存在但为空的字段。你可以试试

如果![应用程序]{mutate{add_field=>{“application”=>“unknown_application”}