Last active
October 29, 2018 11:06
-
-
Save markbirbeck/31b1beafe060fb8eb4c1345b1e75ad5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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