繁体   English   中英

在Logstash conf中建立索引时如何添加文件名

[英]How to add the file name when indexing in logstash conf

我有两个名为access_loghttp_access_2015-03-06_log文件,我想将文件的accesshttp_access_2015-03-06部分设置为索引。

我读了一些类似问题的答案,但我不知道如何使用grok过滤器过滤文件路径并将其用作索引参考。

下面是我的配置文件:

input {
  file {
    path => ["G:/logstash-1.5.0/bin/tmp/*_log"]
    start_position => "beginning"

  }
}

filter {
  if [path] =~ "access" {
    mutate { replace => { type => "apache_access" } }
    grok {
      match => { "message" => "%{COMBINEDAPACHELOG}" }
    }
    date {
      match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
    }
  } else if [path] =~ "error" {
    mutate { replace => { type => "apache_error" } }
  } else {
    mutate { replace => { type => "random_logs" } }
  }
}

output {
  elasticsearch { 
     action => "index"
     host => localhost
     index => "test" 
  }
  stdout { codec => rubydebug }
}

怎么做?

您正在设置“类型”字段。 如果这足够好,您可以在输出{}节中引用它:

index => "%{type}-%{+YYYY.MM.dd}"

如果您想使用过滤器中一些您不想也存储在elasticsearch中的信息,可以将其放在元数据字段中,例如:

[@metadata][myField]

然后以相同的方式引用。

暂无
暂无

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

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