2016-07-27 51 views
1

我有一個logstash啓動並運行,消耗兩個兔子隊列併發送到elasticsearch。這是我的logstash.conf文件:如何使用logstash將隊列的內容發送到elasticsearch索引

input { 
    rabbitmq { 
    host => 'rabbit' 
    durable => true 
    user => 'user' 
    queue => 'dev-user_trace' 
    password => 'pass' 
    } 
    rabbitmq { 
    host => 'rabbit' 
    durable => true 
    user => 'user' 
    queue => 'min-price-queue' 
    password => 'pass' 
    } 

} 
filter{ 
} 
output{ 
    stdout { codec => json} 
    elasticsearch{ 
    hosts => ["elasticsearch"] 
    index => "eventss-%{+YYYY.MM.dd}" 
    } 

} 

現在我有另一個隊列,但我想它的內容發送到不同的elasticsearch指數。我的問題是:我如何需要將特定條目重定向到特定索引?還是我需要另一個logstash實例?

在此先感謝。

回答

3

非常好的開始。現在,你只需要在「類型」每個輸入,然後將事件轉發到給定的類型選擇合適的輸出,這樣的:

input { 
    rabbitmq { 
    host => 'rabbit' 
    durable => true 
    user => 'user' 
    queue => 'dev-user_trace' 
    password => 'pass' 
    type => 'traces'    # <-- add this 
    } 
    rabbitmq { 
    host => 'rabbit' 
    durable => true 
    user => 'user' 
    queue => 'min-price-queue' 
    password => 'pass' 
    type => 'prices'    # <-- add this 
    } 

} 
filter{ 
} 
output{ 
    stdout { codec => json} 

    if [type] == 'traces' {   # <-- check type 
    elasticsearch{ 
     hosts => ["host1:9200"] 
     index => "index1-%{+YYYY.MM.dd}" 
    } 
    } 

    if [type] == 'prices' {   # <-- check type 
    elasticsearch{ 
     hosts => ["host2:9200"] 
     index => "index2-%{+YYYY.MM.dd}" 
    } 
    } 
} 

UPDATE

以上是最常見的方法,讓你可以不同地配置兩個輸出。正如@pandaadb建議,你也可以有一個單一的輸出,並定義一個類型,這將是您的目標指數:

input { 
    rabbitmq { 
    host => 'rabbit' 
    durable => true 
    user => 'user' 
    queue => 'dev-user_trace' 
    password => 'pass' 
    type => 'index1'     # <-- add this 
    } 
    rabbitmq { 
    host => 'rabbit' 
    durable => true 
    user => 'user' 
    queue => 'min-price-queue' 
    password => 'pass' 
    type => 'index2'     # <-- add this 
    } 

} 
filter{ 
} 
output{ 
    stdout { codec => json} 

    elasticsearch{ 
    hosts => ["localhost:9200"] 
    index => "%{type}-%{+YYYY.MM.dd}" # <-- use type here 
    } 
} 
+0

如果你調用由索引名你的類型,你可以在你的索引使用通配符和有1 elasticsearch輸出索引爲「%{type} - %{+ YYYY/MM.dd}」 – pandaadb

+0

@pandaadb是的,但他可能想要配置兩個ES輸出不同,例如發送到兩個不同的ES主機(如我的答案)。我的答案更一般,但是當然,如​​果需要的話,你可以有一個單一的輸出並定義'type'作爲目標索引。我已經更新了我的答案,並因此獲得了信任。 – Val

+0

哦,是的,你的回答絕對正確:)我只是想補充一點,因爲它在我的簡單情況下有所幫助,它使配置更具可讀性我認爲 – pandaadb

相關問題