[NodeJS] bulk 데이터 파일 읽어서 ElasticSearch에 등록하기

[NodeJS] bulk 데이터 파일 읽어서 ElasticSearch에 등록하기

728x90

https://minu0807.tistory.com/114 여기랑 이어지는 내용이기도 함.

const fs = require('fs'); const es_client = require('./client'); async function asyncForEach (array, callback) { for (let index = 0; index < array.length; index++) { await callback(array[index], index, array); } }; async function run() { try { const list = fs.readdirSync('./_bulk/'); asyncForEach(list, async (name) => { console.log(name); let data = fs.readFileSync('./_bulk/' + name, 'utf8'); let bulk = await es_client.bulk({ body: data }) console.log(bulk); }) } catch (err) { console.error(err); } } run();

_bulk 디렉터리에 벌크 데이터가 저장된 파일들이 있고, 그 파일들을 읽어와서 bulk 처리해줌.

파일이 벌크 형식으로 데이터가 제대로 들어있지 않다거나, 형식은 제대로 되어 있는데 엘라스틱 맵핑 정보가 잘못되어 있는 것이 아니라면 크게 오류 날 일은 없다.

https://github.com/smw0807/minu_1/blob/master/node/es_data_make_bulk/run_bulk.js

반응형

from http://minu0807.tistory.com/115 by ccl(A) rewrite - 2021-11-25 10:01:18