diff --git a/lib/Serializer.js b/lib/Serializer.js index a2fae9148..5bb84adfb 100644 --- a/lib/Serializer.js +++ b/lib/Serializer.js @@ -49,7 +49,10 @@ class Serializer { const keys = Object.keys(object) for (var i = 0, len = keys.length; i < len; i++) { var key = keys[i] - if (Array.isArray(object[key]) === true) { + // elasticsearch will complain for keys without a value + if (object[key] === undefined) { + delete object[key] + } else if (Array.isArray(object[key]) === true) { object[key] = object[key].join(',') } } diff --git a/lib/Transport.js b/lib/Transport.js index 22fe090db..eec669d3f 100644 --- a/lib/Transport.js +++ b/lib/Transport.js @@ -34,10 +34,21 @@ class Transport { } request (params, options, callback) { + options = options || {} if (typeof options === 'function') { callback = options options = {} } + + // promises support + if (callback == null) { + return new Promise((resolve, reject) => { + this.request(params, options, (err, result) => { + err ? reject(err) : resolve(result) + }) + }) + } + callback = once(callback) // TODO: return in the result the metadata const meta = {