[英]using elasticsearch filter in logstash pipeline
我在logstash管道中使用了Elasticsearch過濾器。 我使用以下命令正確找到結果:
filter{
if [class] == "DPAPIINTERNAL" {
elasticsearch {
hosts => "10.1.10.16"
index => "dp_audit-2017.02.16"
query_template => "/home/vittorio/Documents/elastic-queries/matching-requestaw.json"
}
}
}
如您所見,我使用“ query_template”,即:
{
"query": {
"query_string": {
"query": "class:DPAPI AND request.aw:%{[aw]}"
}
},
"_source": ["end_point", "vittorio"]
}
告訴elastichsearch使用與DPAPIINTERNAL日志匹配“ aw”的特定類查找日志。
完善! 但現在我找到了結果,因此我想從中添加一些字段並將其附加到我的DPAPIINTERNAL日志中,例如,我想獲取“ end_point”並將其添加到日志中的新鍵“ vittorio”中。
這沒有發生,我不明白為什么。
這是我正在使用查詢查看的日志:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "dp_audit-2017.02.16",
"_type": "logs",
"_id": "AVpHoPHPuEPlW12Qu",
"_score": 1,
"_source": {
"svc": "dp-1.1",
"request": {
"method": "POST|PATCH|DELETE",
"aw": "prova",
"end_point": "/bank/6311",
"app_instance": "7D1-D233-87E1-913"
},
"path": "/home/vittorio/Documents/dpapi1.json",
"@timestamp": "2017-02-16T15:53:33.214Z",
"@version": "1",
"host": "Vito",
"event": "bank.add",
"class": "DPAPI",
"ts": "2017-01-16T19:20:30.125+01:00"
}
}
]
}
}
您需要在elasticsearch
過濾器中指定fields
參數 ,如下所示:
elasticsearch {
hosts => "10.1.10.16"
index => "dp_audit-2017.02.16"
query_template => "/home/vittorio/Documents/elastic-queries/matching-requestaw.json"
fields => { "[request][end_point]" => "vittorio" }
}
請注意,由於end_point
是一個嵌套字段,因此您需要像這樣修改查詢模板中的_source
:
"_source": ["request.end_point"]
問題很簡單,您不必使用query_template指定“新”字段。
"_source": ["request"] # here you specify the field you want from the query result.
接着
filter{
if [class] == "DPAPIINTERNAL" {
elasticsearch {
hosts => "10.1.10.16"
index => "dp_audit-2017.02.16"
query_template => "/home/vittorio/Documents/elastic-queries/matching-requestaw.json"
fields => {"request" => "new_key"} # here you add the fields and will tell elastich filter to put request inside new_key
}
}
}
那對我有用!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.