Created
December 14, 2022 18:11
-
-
Save pmuellr/85c815eb0b62fc9c0dccc4745e9561ab to your computer and use it in GitHub Desktop.
Convert Elasticsearch "hits" JSON response to NDJSON format for easy importing back to Elasticsearch
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
#!/usr/bin/env node | |
const fs = require('fs') | |
const [ fileName ] = process.argv.slice(2) | |
if (fileName == null) { | |
console.error('input file with search response required') | |
process.exit(0) | |
} | |
const contents = fs.readFileSync(fileName, 'utf-8') | |
const json = JSON.parse(contents) | |
const hits = json.hits.hits | |
const output = hits.map(hit => JSON.stringify(hit._source)).join('\n') | |
console.log(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment