如何在具有公共主机的 logstash.conf 文件中创建多个索引

How to create multiple indexes in logstash.conf file with common host

我是 logstash 的新手。

在我们的应用程序中,我们正在创建多个索引,从下面的线程我可以理解如何解决这个问题

但这会导致 conf 文件中出现许多重复行(对于主机、ssl 等)。所以我想检查是否有更好的方法?

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

我可以用下面的东西代替上面的配置吗?

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

您正在寻找的是在 logstash 管道中使用环境变量。您只需定义一次,就可以使用与您对 HOST、SSL 等所说的相同的冗余值。

更多信息Logstash Use Environmental Variables

例如,

output {
  elasticsearch{
    hosts => ${ES_HOST}
    index => "%{type}-indexer"
  }
}

如果有帮助,请告诉我。