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

标签 elasticsearch logstash kibana

我使用以下代码在 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 和 5 中发生了一点变化:

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

关于elasticsearch - 如何在 logstash.conf 文件中创建多个索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33820478/

相关文章:

elasticsearch - 在内部列表上查询Elasticsearch并仅从列表中获取匹配的对象,而不是结果文档中的整个列表

java - Elasticsearch聚合查询

elasticsearch - 在一台机器上运行 Kibana3、LogStash 和 ElasticSearch

elasticsearch - Logstash中的日期翻译以进行Elasticsearch

elasticsearch - 轮胎术语过滤器不起作用

elasticsearch - ElasticSearch查询字段不起作用

linux - 如何在Linux机器上安装多个logstash实例?

elasticsearch - 如何在Logstash ElasticSearch中使用_timestamp

elasticsearch - Kibana KQL可视化过滤器-排除列表字段的一个值

java - 如何在java中执行cURL语句从kibana获取JSON