diff --git a/README.md b/README.md index d2424ef..7b5f90d 100644 --- a/README.md +++ b/README.md @@ -37,16 +37,16 @@ var toBulk = new TransformToBulk(function getIndexTypeId(doc) { return { _id: do require('random-document-stream')(42).pipe(toBulk).pipe(ws).on('finish', done); ``` -NOTE: One must listen to the `close` event emitted by the write stream to know +NOTE: One must listen to the `elasticsearch_streams_close` event emitted by the write stream to know when all the data has been written and flushed to Elasticsearch. Listening to `finish` does not mean much really as we are in this situation: https://github.com/joyent/node/issues/5315#issuecomment-16670354 -For example to close the ES client as soon as we are done: +For example to elasticsearch_streams_close the ES client as soon as we are done: ```js -ws.on('close', function () { +ws.on('elasticsearch_streams_close', function () { client.close(); }); ``` diff --git a/lib/writable-bulk.js b/lib/writable-bulk.js index e58166c..82ae0e8 100644 --- a/lib/writable-bulk.js +++ b/lib/writable-bulk.js @@ -29,7 +29,7 @@ function WritableBulk(bulkExec, highWaterMark) { // Not great. See: https://github.com/joyent/node/issues/5315#issuecomment-16670354 this.on('finish', function() { this._flushBulk(function() { - this.emit('close'); + this.emit('elasticsearch_streams_close'); }.bind(this)); }.bind(this)); } diff --git a/test/test-write.js b/test/test-write.js index 6c4bbf2..db7399d 100644 --- a/test/test-write.js +++ b/test/test-write.js @@ -21,7 +21,7 @@ describe('When writing', function() { ws = new WritableBulk(bulkExec); ws.on('error', function(e) { err = e; - }).on('close', function() { + }).on('elasticsearch_streams_close', function() { done(err); });