diff --git a/CHANGELOG.md b/CHANGELOG.md index 63e301c..bc7f07f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [0.1.2] - 2015-11-16 +### Fixed +- Log right amount of records. The records count that was logged was + doubled in previous release. + ## [0.1.1] - 2015-11-16 ### Fixed - Do not write if there are no records in the queue when the stream gets closed diff --git a/index.js b/index.js index 34e9625..0f27d30 100644 --- a/index.js +++ b/index.js @@ -67,10 +67,6 @@ function ElasticsearchBulkIndexWritable(client, options) { * @param {Function} callback */ ElasticsearchBulkIndexWritable.prototype.bulkWrite = function bulkWrite(records, callback) { - if (this.logger) { - this.logger.debug('Writing %d records to Elasticsearch', records.length); - } - this.client.bulk({ body: records }, function bulkCallback(err, data) { if (err) { err.records = records; @@ -95,10 +91,6 @@ ElasticsearchBulkIndexWritable.prototype.bulkWrite = function bulkWrite(records, return callback(error); } - if (this.logger) { - this.logger.info('Wrote %d records to Elasticsearch', records.length); - } - callback(); }.bind(this)); }; @@ -121,11 +113,19 @@ ElasticsearchBulkIndexWritable.prototype._flush = function _flush(callback) { return callback(error); } + if (this.logger) { + this.logger.debug('Writing %d records to Elasticsearch', this.queue.length); + } + this.bulkWrite(records, function(err) { if (err) { return callback(err); } + if (this.logger) { + this.logger.info('Wrote %d records to Elasticsearch', this.queue.length); + } + this.writtenRecords += this.queue.length; this.queue = []; diff --git a/package.json b/package.json index 860149a..26e3ac1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "elasticsearch-bulk-index-stream", - "version": "0.1.1", + "version": "0.1.2", "description": "A writable stream for bulk indexing records in Elasticsearch", "main": "index.js", "scripts": {