@sagacify/csv2es
v1.0.1
Published
Stream your csv to ElasticSearch
Downloads
4
Maintainers
Readme
csv2es
Stream your csv to your Elasticsearch !
Installation
$ npm install csv2es
Requirement
The csv file/stream first line must contain the headers
Usage
Import in your project
// require csv2es
const { csv2es } = require('csv2es');
// import csv2es
import { csv2es } from 'csv2es';
Stream a csv file to Elasticsearch
const elasticsearch = require('http://localhost:9200');
const fs = require('fs');
const main = async () => {
const fileStream = fs.createReadStream('/path/to/file.csv');
const client = new elasticsearch.Client({
node:
});
await csv2es(csvStream, client, index, {
bom: true,
delimiter: ',',
quote: "'",
escape: "'",
idField: ['ID'],
jsonFields: ['jsonField1', 'jsonField2'],
bulkSize: 500
});
}
main();
Api
csv2es(csvStream, client, index, [options])
Returns: Promise
parameters
csvStream
<stream.Readable> (required) the csv streamclient
(required) see: elasticsearchindex
(required) name of the elasticsearch index
options
bom
(default: false) indicate if the file contains a BOM (use when your file is an export from excel)delimiter
(default: ',') single character used as column spearatorquote
(default: '"') single character used to delimit a fieldescape
(default: '"') single character used escape value in a quoted fieldidField
(default: '') name of the field value that should be used as id for the eslasticsearch indexjsonFields
(default: []) list of the fields that needs to be JSON parsedbulkSize
(default: 100) number of rows that needs to be sent by bulk operation on elasticsearch
Npm scripts
Running lint tests
$ npm test:lint
Running tests
$ npm test:spec
Running coverage tests
$ npm test:cover
This will create a coverage folder with all the report in coverage/index.html
Running all tests
$ npm test
Note: that's the one you want to use most of the time
Reporting bugs and contributing
If you want to report a bug or request a feature, please open an issue.
If want to help us improve autoroute, fork and make a pull request.
Please use commit format as described here.
And don't forget to run npm run format
before pushing commit.
Repository
License
The MIT License (MIT)
Copyright (c) 2021 Sagacify
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.