在 Mapping 里面,将 dynamic 参数设置成 strict 可以拒绝索引包含未知字段的文档。 此条 Tips 由 medcl 贡献。

filebeat收集多个路径下的日志,在logstash中如何为这些日志分片设置索引或者如何直接在filebeat文件中设置索引直接存到es中

Beats | 作者 PhoebM | 发布于2018年03月28日 | 阅读数:8122

filebeat收集多个路径下的日志,
在logstash中如何根据路径为这些日志分片设置索引
或者如何直接在filebeat文件中设置索引直接存到es中
 
 
 
 
已邀请:

shitangjiejie

赞同来自: muou vlgnaw

filebeat里添加document_type配置,定义一个识别号- input_type: log

  # Paths that should be crawled and fetched. Glob based paths.
  paths:
    - /var/logs/xx.log
  document_type: xx
  paths:
    - /data/logs/aa.log
  document_type: aa
 
然后在logstash里配置对应的type
output {
    if [type] =="xx"{
            elasticsearch {
            hosts => ["*.*.*.*:9200"]
            index => "xx-%{+YYYY.MM.dd}"
            document_type => "log"
        }
    }
    if [type] =="aa"{
            elasticsearch {
              hosts => ["*.*.*.*:9200"]
              index => "aa-%{+YYYY.MM.dd}"
              document_type => "log"
                }
    }
}
你试下

yuzerk

赞同来自: vlgnaw

首先 你在filebeat 中的filebeat.prospectors 配置项下 为每一个采集的数据增加一个表明身份的indexname,例如
 
processors:
- drop_fields:
    fields:
    - beat
fields:
  host: xxxx.xxxx.xxxx.xxxx
logging.level: info
fields_under_root: true
filebeat.prospectors:
- multiline.pattern: ^\[?[0-9]{4}-[0-9]{2}-[0-9]{2}
  paths:
  - /xxxxxxx/xxxx/xxxx/xxx/*.log
  scan_frequency: 5s
  multiline.match: after
  fields:
    indexname: logs_xxxxx
  input_type: log
  multiline.negate: true
  close_inactive: 2m
  fields_under_root: true
output.logstash:
  compression_level: 3
  hosts:
  - xxxx.xxxx.xxxx.xxxx:5044
 
然后可以在logstash.conf 里配置

input{
beats{
port => 5044
}
}
output{
elasticsearch{
hosts => ["http://localhost:9200"]
index => "%{indexname}-%{+YYYY-MM-dd}"
}
}
 
希望能够帮到你
 

要回复问题请先登录注册