Json file with logstash

I converted a csv file to a json file. How to read this file with logstash and put in elasticsearch. I don't see any error. My json file looks like this:

[{"LOR": "LOR ", "CGPA": "CGPA", "TOEFL Score": "TOEFL Score", "GRE Score": "GRE Score", "Serial No": "Serial No", "SOP": "SOP", "Chance of Admit": "Chance of Admit ", "University Rating": "University Rating", "Research": "Research"}, {"LOR": "4.5", "CGPA": "9.65", "TOEFL Score": "118", "GRE Score": "337", "Serial No": "1", "SOP": "4.5", "Chance of Admit": "0.82", "University Rating": "4", "Research": "1"}, {"LOR": "4.5", "CGPA": "8.87", "TOEFL Score": "107", "GRE Score": "324", "Serial No": "2", "SOP": "4", "Chance of Admit": "0.76", "University Rating": "4", "Research": "1"},

There is more.

my logstash config file is like this:

`input {
file{
	codec =>json
    
	path => "/home/abhinavkumar.gurung/Applications/csv/devian/data/file.json"
	start_position => "beginning"
	sincedb_path => "/dev/null"
}

}
filter {
json{
source =>"message"
}
mutate{
remove_field => ["@version","host"]
}
}
output {
elasticsearch {
hosts => ["elasticsearch:9200"]
user => elastic
password => changeme
index => "markers"
}
stdout {
codec => rubydebug
}
}`

Do you see anything in the rubydebug that you are using?

I have tried with minimal config and everything looks fine on my side. Can you please check and compare your config's with this .

A sample json file with the below content.

{"menu": {"id": "file","value": "File","popup": {"menuitem": [{"value": "New", "onclick": "CreateNewDoc()"},{"value": "Open", "onclick": "OpenDoc()"},{"value": "Close", "onclick": "CloseDoc()"}]}}}

My Logstash conf file :

input {
    file {
        path => "path-to-file/sample.json"
        start_position => "beginning"
	}
}
filter{
	json{
		source =>  "message"
	}
}
output
{
	elasticsearch{
		hosts => [ "localhost:9200" ]
		index  => [ "test-file-%{+YYYY.MM.dd}" ]
	}
	stdout { codec => rubydebug }
}

Here is my Elasticsearch output.

I'm not sure why you want to convert csv to json , because Logstash has csv filter too. Check the below link once to understand how to use csv filter.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.