I have a json file with 1000 json object. is there any way to add a header line before each json document ? Is there any easiest way ?
Example : I have 1000 object l
If you are willing to leverage Logstash, you don't need to modify your file and can simply read it line by line and stream it to ES using the elasticsearch
output which leverages the Bulk API.
Store the following Logstash configuration in a file named es.conf
(make sure the file path
and ES hosts
match your settings):
input {
file {
path => "/path/to/your/json"
sincedb_path => "/dev/null"
start_position => "beginning"
codec => "json"
}
}
filter {
mutate {
remove_fields => ["@version", "@timestamp"]
}
}
output {
elasticsearch {
hosts => "localhost:9200"
index => "test"
document_type => "type1"
document_id => "%{id}"
}
}
Then, you need to install logstash and you'll be able to run the following command in order to load your JSON files to your ES server:
bin/logstash -f es.conf
I found the best way to Add a header line before each json document. https://stackoverflow.com/a/30899000/5029432