Skip to content

Instantly share code, notes, and snippets.

@markbirbeck
Last active October 29, 2018 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markbirbeck/31b1beafe060fb8eb4c1345b1e75ad5d to your computer and use it in GitHub Desktop.
Save markbirbeck/31b1beafe060fb8eb4c1345b1e75ad5d to your computer and use it in GitHub Desktop.
class ElasticSearchWritableStream extends stream.Writable {
constructor(config) {
...
}
/**
* When writing a single record, we use the index() method of
* the ES API:
*/
async _write(body, enc, next) {
/**
* Push the object to ES and indicate that we are ready for the next one.
* Be sure to propagate any errors:
*/
try {
await this.client.index({
index: this.config.index,
type: this.config.type,
body
})
next()
} catch(err) {
next(err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment