elasticsearch 如何在logstash.conf文件中创建多个索引?,elasticsearch,logstash,kibana,elasticsearch,Logstash,Kibana" /> elasticsearch 如何在logstash.conf文件中创建多个索引?,elasticsearch,logstash,kibana,elasticsearch,Logstash,Kibana" />

elasticsearch 如何在logstash.conf文件中创建多个索引?

elasticsearch 如何在logstash.conf文件中创建多个索引?,elasticsearch,logstash,kibana,elasticsearch,Logstash,Kibana,我使用以下代码在logstash.conf中创建了一个索引 output { stdout {codec => rubydebug} elasticsearch { host => "localhost" protocol => "http" index => "trial_indexer" } } 要创建另一个索引,我通常会在上面的代码中将索引名替换为另一个索引名。有没

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

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

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

您可以根据某个字段的值在索引名中使用模式。在这里,我们使用
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和Logstash 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
可以在任何地方定义,无论是在输入部分还是过滤器部分。唯一的问题是输入错误,您需要使用
%{index}
而不是
${index}
@Val我在Logstash文档中花了很长时间才找到这个问题的答案,所以非常感谢您将其清除。为StackOverflow再评分一分。
如果[type]=“trial”&&&[msg]=“yes”
我可以在输出中使用和条件吗@Val@AATHITHRAJENDRAN当然可以