2017-02-16 6 views
0

私はlogstashパイプラインでelasticsearchフィルタを使用しています。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」を使用して::

「一致する特定のクラスでログを検索するelastichsearchを伝え
{ 
    "query": { 
     "query_string": { 
     "query": "class:DPAPI AND request.aw:%{[aw]}" 
     } 
    }, 
    "_source": ["end_point", "vittorio"] 
} 

AWを私は正しく使用して結果を見つけますDPAPIINTERNALログと比較します。

完璧!しかし、今私は結果を見つけたので、私はそれからいくつかのフィールドを追加し、私の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" 
     } 
     } 
    ] 
    } 
} 

答えて

0

このように、あなたのelasticsearchフィルタでfields parameterを指定するあなたの必要性:

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"] 
+0

"_source":["end_point"、 "vittorio"] – ennon

+0

テンプレートでは、検索するフィールドを指定しますが、 'fields'これらのフィールドをイベントに実際に割り当てます。 – Val

+0

私はちょうどしました、私は新しいフィールドでnull値を持っています。 : – ennon

0

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 
    } 
    } 
}