Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support: keep continue on error #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,9 @@ Usage: es-import-bulk [options]
-v, --version output the version number
-u, --url <url> the elasticsearch url to connect to
-f, --file <file> the file to read data from
-m, --max <items> the max number of lines to process per batch (default: 20,000) (default: 20000)
--requestTimeout <ms> ES CLIENT OPTION: milliseconds before an HTTP request will be aborted and retried. This can also be set per request (default: 30000) (default: 30000)
-m, --max <items> the max number of lines to process per batch (default: 20,000)
--requestTimeout <ms> ES CLIENT OPTION: milliseconds before an HTTP request will be aborted and retried. This can also be set per request (default: 30,000)
-i, --ignore-error ignore error when importing lines, print it to stderr. This allows us to manually handle failed documents after importing
-h, --help output usage information
```

Expand Down
19 changes: 16 additions & 3 deletions lib/es-import-bulk.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ program
helpers.integer,
30000
)
.option('-i, --ignore-error', 'Ignore error when importing lines, print it to stderr. This allows us to manually handle failed documents after importing')
.parse(process.argv);

// validate url and file
Expand All @@ -60,11 +61,23 @@ var client = new elasticsearch.Client({
var bulkImport = function(cb) {
client.bulk({ body: currentBatch }, function(err, response) {
if (err) {
helpers.exit(err);
if (program.ignoreError) {
helpers.logError(err);
}
else {
helpers.exit(err);
}
}
if (response.error) {
helpers.exit('When executing bulk query: ' + response.error.toString());
else if (response.error) {
const errorMessage = 'When executing bulk query: ' + response.error.toString();
if (program.ignoreError) {
helpers.logError(errorMessage);
}
else {
helpers.exit(errorMessage);
}
}

// reset global variables
currentCount = 0;
currentBatch = '';
Expand Down
6 changes: 5 additions & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// a few helper functions
'use strict';

exports.exit = function(err) {
exports.logError = function(err) {
var str = JSON.stringify(err).replace(/^error:/i, '');
console.error('\n error: ' + str);
};

exports.exit = function(err) {
exports.logError(err);
process.exit(1);
};

Expand Down