【问题标题】:How to create multiple indexes in logstash.conf file?如何在 logstash.conf 文件中创建多个索引?
【发布时间】:2015-11-20 06:41:12
【问题描述】:

我使用以下代码在 logstash.conf 中创建了一个索引

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

要创建另一个索引,我通常将上面代码中的索引名称替换为另一个索引名称。有没有办法在同一个文件中创建多个索引?我是 ELK 的新手。

【问题讨论】:

    标签: elasticsearch logstash kibana


    【解决方案1】:

    您可以根据其中一个字段的值在索引名称中使用模式。这里我们使用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"   
            }
        }
    } 
    

    更新

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

    【讨论】:

    • 您指的是“输入”部分中声明的“类型”吗?如果是这样,有没有办法将我正在记录的实际 redis 事件中的一个字段用作索引?
    • @Kepedizer type 可以在任何地方定义,无论是在输入部分还是在过滤部分。唯一的问题in your other question 是一个错字,你需要使用%{index} 而不是${index}
    • @Val 我很难在 Logstash 文档中找到这个问题的答案,所以非常感谢你清理它。为 StackOverflow 再添一分。
    • if [type] == "trial" && [msg] == "yes" 我可以在输出中使用和条件吗? @Val
    • @AATHITHRAJENDRAN 肯定是的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-19
    • 2020-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-05
    • 2017-03-07
    相关资源
    最近更新 更多