gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 02:43:53 27 4
gpt4 key购买 nike

我使用以下代码在 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com