簡體   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