07 Logstash 去除不需要的字段

架构说明:
192.168.189.83 Kibana Elasticsearch
192.168.189.84 Logstash、Nginx



去除不需要的字段:
只能去除 _source 里面的字段,非 _source 里面的去除不了。 

+++++++++++ 去除不需要的字段:
vim /usr/local/logstash-6.6.0/config/logstash.conf
input {
file {
path=>"/usr/local/nginx/logs/access.log"
}
}
filter {
grok {
match => {
"message"=>'(?<clientIP>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) - - \[(?<requesttime>[^ ]+ \+[0-9]+)\] "(?<requesttype>[A-Z]+) (?<requesturl>[^ ]+) HTTP/\d.\d" (?<status>[0-9]+) (?<bodysize>[0-9]+) "[^"]+" "(?<ua>[^"]+)"'
 }
remove_field => ["message","@version","path"]
 }
}
output {
if "_grokparsefailure" not in [tags] and "_dateparsefailure" not in [tags] {
elasticsearch {
hosts=>["http://192.168.189.83:9200"]
 }
}
}
保存退出,重启logstash



http://192.168.189.84 刷新网页。 再次触发日志
Kibana查看日志:



会发现少了刚才去除的字段。
去除字段好处:
减少ES数据库的大小
提升搜索效率