­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ const {Client} = require('@elastic/elasticsearch'); const debug = require('debug')('elasticsearch-bunyan'); class ElasticSearch { constructor(clientConfig, indexConfig) { this.client = new Client(clientConfig); this.index = indexConfig; } async write(data) { try { if (typeof data !== 'object') { throw new Error('Type Error: ElasticSearch transport requires log data to be an object'); } await this.client.index({ body: data, ...this.index }); } catch (error) { debug('Failed to ship log', error.message); } } } module.exports = ElasticSearch;