Search code examples
elasticsearchlogstash-configuration

logstash elastic search output configuration based on inputs


Is there any way I can use logstash configuration file to scale output accordingly with different types/indexes ?

For eg.,

output {
 elasticsearch {
    hosts => ["localhost:9200"]
    index => "index_resources"
    if(%{some_field_id}==kb){
         document_type => "document_type"
         document_id => "%{some_id}"
    }
   else {
        document_type => "other_document_type"
        document_id => "%{some_other_id}"
   }
}

Solution

  • Yes you could route your documents to multiple indexes within your logstash itself. Output could look something like this:

    output {  
        stdout {codec => rubydebug}
        if %{some_field_id} == "kb" {  <---- insert your condition here
            elasticsearch {  
                host => "localhost"  
                protocol => "http"  
                index => "index1"
                document_type => "document_type"
                document_id => "%{some_id}"   
            }
        } else {
            elasticsearch {  
                host => "localhost"  
                protocol => "http"  
                index => "index2"
                document_type => "other_document_type"
                document_id => "%{some_other_id}"   
            }
        }
    }
    

    This thread might help you as well.