背景
最近在搗鼓Filebeat監(jiān)聽springboot的日志然后將其傳入到es中。這個(gè)時(shí)候日志肯定要切分單獨(dú)字段存儲(chǔ)。這個(gè)時(shí)候用到了es自帶的ingest node pipeline 功能,使用grok 使用正則將log進(jìn)行切分
具體實(shí)現(xiàn)
參考資料:https://www.elastic.co/guide/en/beats/filebeat/current/configuring-ingest-node.html
這篇文檔很詳細(xì)了說明了Filebeat怎么去傳入數(shù)據(jù)
1、配置filebeat.yml
添加如下配置
output.elasticsearch:
pipeline: "test-pipeline" //這里這個(gè)名稱和es上注冊(cè)pipeline的名稱相同
2、在es上注冊(cè)pipeline
根據(jù)對(duì)應(yīng)的json文件注冊(cè)pipeline,使用命令
curl -H "Content-Type: application/json" -XPUT 'http://10.130.7.207:9200/_ingest/pipeline/test-pipeline' -d@/home/hadoop/zgh/log/pipeline.json
這樣的話就可以了,在對(duì)應(yīng)的pipeline.json寫上相應(yīng)的grok就可以了。
對(duì)應(yīng)的json文件陽(yáng)歷(會(huì)在grok相關(guān)文章詳細(xì)解釋)
{
"description" : "test-pipeline",
"processors": [
{
"grok": {
"field": "message",
"patterns": ["%{TIMESTAMP_ISO8601:client} %{GREEDYDATA:method} %{LOGLEVEL:request} %{GREEDYDATA:demo} %{ALL_CODE:messageaaa}" ],
"pattern_definitions" : {
"ALL_CODE" : "(.|\n)*"
}
}
}
]
}