Ankush Ganatra
Ankush Ganatra

Reputation: 510

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

I am pretty new to logstash.

In our application we are creating multiple indexes, from the below thread i could understand how to resolve that How to create multiple indexes in logstash.conf file?

but that results in many duplicate lines in the conf file (for host, ssl, etc.). So i wanted to check if there is any better way of doing it?

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

Instead of above config, can i have something like below?

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

Upvotes: 0

Views: 1078

Answers (1)

mohdasha
mohdasha

Reputation: 311

What you are looking for is using Environment Variables in logstash pipeline. You define this once, and can use same redundant values like you said for HOST, SSL etc.

For more information Logstash Use Environmental Variables

e.g.,

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

Let me know, if that helps.

Upvotes: 1

Related Questions