Add a header line before each json document

前端 未结 2 1115
说谎
说谎 2021-01-26 13:33

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

相关标签:
2条回答
  • 2021-01-26 13:47

    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
    
    0 讨论(0)
  • 2021-01-26 13:59

    I found the best way to Add a header line before each json document. https://stackoverflow.com/a/30899000/5029432

    0 讨论(0)
提交回复
热议问题