elastic-batch-file

1.0.0 • Public • Published

Elasticsearch _bulk File

The easiest way to get large amounts of data into an Elasticsearch index is by using the _bulk API.

This script creates _bulk-compatible files from regular JavaScript arrays.

Usage

const batch = require('elastic-batch-file')
const arr = [
  { id: 'hello', name: 'world' },
  { id: 'whats', name: 'up' }
]

batch(arr, 'indexname', 'out')

The file can be sent straight to Elasticsearch:

curl -s -H "Content-Type: application/x-ndjson" -u 'elastic:auth' "https://elastic-db:port/_bulk" --data-binary "@batch_indexname"; echo

Parameters

  • arr: Array of Objects. Each entry requires an "id" field
  • indexname: the name of the index for the bulk operation
  • outfile: which file to write in the current directory. Starts with batch_

Output

{"index":{"_index":"indexname","_type":"_doc","_id":"hello"}}
{"name":"world"}
{"index":{"_index":"indexname","_type":"_doc","_id":"whats"}}
{"name":"up"}

License

MIT © Patrick Heneise

Package Sidebar

Install

npm i elastic-batch-file

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

6.14 kB

Total Files

7

Last publish

Collaborators

  • patrickheneise