rittenhop-dev/versions/5.94.2/node_modules/@tryghost/elasticsearch/lib/ElasticSearchBunyan.js
2024-09-23 19:40:12 -04:00

33 lines
866 B
JavaScript

const ElasticSearch = require('./ElasticSearch');
const {PassThrough} = require('stream');
const split = require('split2');
// Create a writable stream which pipes data written into it, into the bulk helper
class ElasticSearchBunyan {
constructor(clientConfig, index, pipeline) {
this.client = new ElasticSearch(clientConfig);
this.index = index;
this.pipeline = pipeline;
}
getStream() {
const index = this.index;
const pipeline = this.pipeline;
const stream = new PassThrough();
this.client.client.helpers.bulk({
datasource: stream.pipe(split()),
onDocument() {
return {
create: {_index: index}
};
},
pipeline
});
return stream;
}
}
module.exports = ElasticSearchBunyan;