Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Pass along errors to the CB when creating an ES client. Before those …

…were clobbered. Better API.

Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
  • Loading branch information...
commit bad3215e3f01ea3877cd4b23146fb2e8057eb556 1 parent 1739160
Nick Campbell authored
2  lib/elasticsearch.js
View
@@ -17,7 +17,7 @@ function ElasticSearch(args) {
var self = this;
this.index.create(function(err, res) {
if (cb) {
- cb(self);
+ cb(err, self);
}
});
} else {
18 lib/index.js
View
@@ -1,13 +1,12 @@
-var utils = require('./utils');
+var utils = require('./utils'),
+ util = require('sys');
function Index(opts) {
if (!opts) {
throw new Error('Must specify config options.');
}
- if (!(opts.deleting)) {
- if (!(opts.name)) {
- throw new Error('Must specify an index name.');
- }
+ if (!(opts.name)) {
+ throw new Error('Must specify an index name.');
}
this.name = opts.name;
@@ -43,21 +42,20 @@ Index.prototype.refresh = function(opts, cb) {
}
Index.prototype.create = function(opts, config, cb) {
- if (opts && !(config || cb) && typeof(opts) == 'function') {
+ if (opts && !(config && cb) && typeof(opts) == 'function') {
cb = opts;
- config = {}
+ config = {settings: {index: {number_of_shards: 5, number_of_replicas: 1}}};
opts = {};
} else if (config && !cb && typeof(config) == 'function') {
cb = config;
- config = {}
+ config = {settings: {index: {number_of_shards: 5, number_of_replicas: 1}}};
}
- config = utils.mapConfig({settings: {number_of_shards: 5, number_of_replicas: 1}}, config);
var req_opts = {
method: ((config.mappings)?'POST':'PUT'),
path: '/'+this.name+'/'
};
- utils.request(utils.mapConfig(utils.default_config, req_opts, opts), config, cb);
+ utils.request(utils.mapConfig(utils.default_config, req_opts, opts), utils.mapConfig(config, this.idx_config), cb);
}
Index.prototype.delete = function(cb) {
2  tests/suites/test-iface.js
View
@@ -8,7 +8,7 @@ module.exports = {
'check init index': function(assert) {
assert.expect(2);
var idx_name = 'test'+(new Date()).getTime();
- var index = new Index({name: idx_name});
+ var index = new Index({name: idx_name});
assert.equal(index.name, idx_name);
assert.deepEqual(index.idx_config, {});
assert.done();
7 tests/utils.js
View
@@ -8,7 +8,10 @@ function clientTestCase(suite) {
suite.setUp = function(done) {
var self = this,
idx_name = 'test'+(new Date()).getTime();
- lib.createClient({index: idx_name}, function(client) {
+ lib.createClient({index: idx_name}, function(err, client) {
+ if (err) {
+ self.fail(err);
+ }
self.client = client;
done();
});
@@ -21,7 +24,6 @@ function clientTestCase(suite) {
return clientTestCase.super_.call(this, suite);
}
-
util.inherits(clientTestCase, nodeunit.testCase);
exports.clientTestCase = clientTestCase;
@@ -43,6 +45,5 @@ function indexTestCase(suite) {
return indexTestCase.super_.call(this, suite);
}
-
util.inherits(indexTestCase, nodeunit.testCase);
exports.indexTestCase = indexTestCase;
Please sign in to comment.
Something went wrong with that request. Please try again.