Logstash詳解之——output模組

ritit發表於2017-09-06

Logstash的output模組,相比於input模組來說是一個輸出模組,output模組整合了大量的輸出外掛,可以輸出到指定檔案,也可輸出到指定的網路埠,當然也可以輸出資料到ES.
在這裡我只介紹如何輸出到ES,至於如何輸出到埠和指定檔案,有很多的文件資料可查詢.

  elasticsearch{  
    hosts=>["172.132.12.3:9200"]  
    action=>"index"  
    index=>"indextemplate-logstash"  
    #document_type=>"%{@type}"  
    document_id=>"ignore"  
      
    template=>"/opt/logstash-conf/es-template.json"  
    template_name=>"es-template.json"  
    template_overwrite=>true       
    }

action=>”index” #es要執行的動作 index, delete, create, update
l index:將logstash.時間索引到一個文件
l delete:根據id刪除一個document(這個動作需要一個id)
l create:建立一個索引document,如果id存在 動作失敗.
l update:根據id更新一個document,有一種特殊情況可以upsert–如果document不是已經存在的情況更新document 。參見upsert選項。
l A sprintf style string to change the action based on the content of the event. The value %{[foo]} would use the foo field for the action
document_id=>” ” 為索引提供document id ,對重寫elasticsearch中相同id詞目很有用
document_type=>” ”事件要被寫入的document type,一般要將相似事件寫入同一type,可用%{}引用事件type,預設type=log
index=>”logstash-%{+YYYY,MM.dd}” 事件要被寫進的索引,可是動態的用%{foo}語句
hosts=>[“127.0.0.0”] [“127.0.0.1:9200″,”127.0.0.2:9200”] “https://127.0.0.1:9200”
manage_template=>true 一個預設的es mapping 模板將啟用(除非設定為false 用自己的template)
template=>”” 有效的filepath 設定自己的template檔案路徑,不設定就用已有的
template_name=>”logstash” 在es內部模板的名字
這裡需要十分注意的一個問題是,document_id儘量保證值得唯一,這樣會解決你面即將面臨的ES資料重複問題,切記切記!


相關文章