Gibbs Kim's playground

[ElasticStack-5] .csv file insert to Elasticsearch via Logstash.conf 본문

Tech 기록지/Elastic Stack

[ElasticStack-5] .csv file insert to Elasticsearch via Logstash.conf

Lio Grande 2020. 4. 6. 17:27

 

Logstash를 사용하여 파일(대표적으로 .csv)을 Elasticsearch로 업로드할때 사용하는 대표적인 파일명은 다음과 같은 패턴을 가진다 -> logstash2el.conf

.conf 파일은 대표적으로 input, filter, output 을 사용하여 raw data를 입력(input)하고 정제(filter)하며, ES로 파일을 전송(output)한다.

 

=================== .conf Example ====================

## This is operated in ELK 7.6.2
input {
	file {
    	## Basically, Windows' path like as C:\Users\~
        ## In Logstash, Windows also follow linux style path
    	path => "C:/sampleFolder/text.csv"
        start_position => "beginning"
        ## in this case is Winodws
        ## Linux; sincedb_path => "/dev/null"
        sincedb_path => "nul"
    }
}

filter {
	csv {
    	separator => ","
        columns => "time", "airline", "responsetime"]
    }
    
    data {
    	match => ["time", "yyyy/MM/dd HH:mm:ss Z"]
    }
    
    mutate {convert => ["airline", "string"]}
    mutate {convert => ["responsetime", "float"]}
}

output {
	elasticsearch {
    	## port is setted internally
    	hosts => "localhost"
        ## when you make index patterns in Kibana like below,
        ## you must use lowercase
        index => "logstash2eltest"
    }
    
    stdout {
    	codec => rubydebug
    }
}

관련하여 참고할만한 링크들

1. Logstash grok

2. Logstash configuration Example

3. sincedb_path Windows/Linux issue