Skip to content

Instantly share code, notes, and snippets.

@romiras
Last active November 11, 2021 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romiras/21e272708141b41451dabdda8ea12b49 to your computer and use it in GitHub Desktop.
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.
# 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