Ensure aggResp is valid before putting it in an array (#16989) (#17060)

This commit is contained in:
Tim Roes 2018-03-09 12:22:10 +01:00 committed by GitHub
parent 4f2b0fb518
commit 3c646eb842
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,10 +5,12 @@ export function AggResponseBucketsProvider() {
function Buckets(aggResp, aggParams) {
if (_.has(aggResp, 'buckets')) {
this.buckets = aggResp.buckets;
} else {
} else if (aggResp) {
// Some Bucket Aggs only return a single bucket (like filter).
// In those instances, the aggResp is the content of the single bucket.
this.buckets = [aggResp];
} else {
this.buckets = [];
}
this.objectMode = _.isPlainObject(this.buckets);