Last active
November 11, 2021 10:57
-
-
Save romiras/21e272708141b41451dabdda8ea12b49 to your computer and use it in GitHub Desktop.
A script for transforming .jsonl file into file ready for bulk import to ES.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reads .jsonl file and transforms it into file ready for bulk import to ES. | |
require 'json' | |
File.open(ARGV[1], 'wb') {|f| | |
ARGF.each_line { |line| | |
a = JSON.parse(line) | |
out = { | |
index: { | |
"_id": a["_id"], | |
"_index": a["_index"], | |
} | |
} | |
f.write(out.to_json); f.write("\n") | |
f.write(a["_source"].to_json); f.write("\n") | |
} | |
} | |
# run: | |
# bundle exec ruby es_ndjson_split.rb dest.ndjson < orig_documents.jsonl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment