2015-11-20 98 views
12

我用下面的代碼段來創建在logstash.conf索引如何在logstash.conf文件中創建多個索引?

output { 
    stdout {codec => rubydebug} 
    elasticsearch { 
     host => "localhost" 
     protocol => "http" 
     index => "trial_indexer" 
    } 
} 

要創建另一個索引i一般與另一種在上面的代碼替換索引名。有沒有在同一個文件中創建多個索引的方法?我是新來的ELK。

回答

34

您可以根據其中一個字段的值使用索引名稱中的模式。這裏我們使用type字段的值,以命名索引:

output { 
    stdout {codec => rubydebug} 
    elasticsearch { 
     host => "localhost" 
     protocol => "http" 
     index => "%{type}_indexer" 
    } 
} 

您也可以使用多個elasticsearch輸出到同一ES主機或不同的ES主機:

output { 
    stdout {codec => rubydebug} 
    elasticsearch { 
     host => "localhost" 
     protocol => "http" 
     index => "trial_indexer" 
    } 
    elasticsearch { 
     host => "localhost" 
     protocol => "http" 
     index => "movie_indexer" 
    } 
} 

或者也許你想給你的路線文件,基於一些變量不同的指標:

output { 
    stdout {codec => rubydebug} 
    if [type] == "trial" { 
     elasticsearch { 
      host => "localhost" 
      protocol => "http" 
      index => "trial_indexer" 
     } 
    } else { 
     elasticsearch { 
      host => "localhost" 
      protocol => "http" 
      index => "movie_indexer" 
     } 
    } 
} 

UPDATE

的語法已經改變一點點Logstash 2和5:

output { 
    stdout {codec => rubydebug} 
    if [type] == "trial" { 
     elasticsearch { 
      hosts => "localhost:9200" 
      index => "trial_indexer" 
     } 
    } else { 
     elasticsearch { 
      hosts => "localhost:9200" 
      index => "movie_indexer" 
     } 
    } 
} 
+0

你指的「類型」中的「輸入」部分聲明?如果是這樣,是否有一種方法可以用作我登錄的實際redis事件中的字段之一? – Kepedizer

+1

@Kepedizer'type'可以在任何地方定義,無論是在輸入部分還是在過濾器部分。唯一的問題[在你的其他問題](http://stackoverflow.com/questions/41531883/logstash-wont-pass-index-from-redis)是一個錯字,你需要使用'%{index}'而不是'$ {index}' – Val

+0

@Val我在試圖在Logstash文檔中追查這個問題的答案時非常糟糕,所以非常感謝您對它進行清理。爲StackOverflow得分另一個。 –