fix(Elasticsearch): fix for alias patterns that refers to term that is numeric zero, fixes #7323

This commit is contained in:
Torkel Ödegaard
2017-01-23 10:15:02 +01:00
parent 8eae09e5e6
commit 697d0867fa
3 changed files with 18 additions and 6 deletions

View File

@@ -166,7 +166,7 @@ function (_, queryDef) {
for (var nameIndex in esAgg.buckets) {
bucket = esAgg.buckets[nameIndex];
props = _.clone(props);
if (bucket.key) {
if (bucket.key !== void 0) {
props[aggDef.field] = bucket.key;
} else {
props["filter"] = nameIndex;
@@ -199,7 +199,7 @@ function (_, queryDef) {
var group = g1 || g2;
if (group.indexOf('term ') === 0) { return series.props[group.substring(5)]; }
if (series.props[group]) { return series.props[group]; }
if (series.props[group] !== void 0) { return series.props[group]; }
if (group === 'metric') { return metricName; }
if (group === 'field') { return series.field; }

View File

@@ -302,7 +302,7 @@ describe('ElasticResponse', function() {
targets = [{
refId: 'A',
metrics: [{type: 'count', id: '1'}],
alias: '{{term @host}} {{metric}} and!',
alias: '{{term @host}} {{metric}} and {{not_exist}} {{@host}}',
bucketAggs: [
{type: 'terms', field: '@host', id: '2'},
{type: 'date_histogram', field: '@timestamp', id: '3'}
@@ -333,6 +333,16 @@ describe('ElasticResponse', function() {
doc_count: 10,
key: 'server2',
},
{
"3": {
buckets: [
{doc_count: 2, key: 1000},
{doc_count: 8, key: 2000}
]
},
doc_count: 10,
key: 0,
},
]
}
}
@@ -343,10 +353,11 @@ describe('ElasticResponse', function() {
});
it('should return 2 series', function() {
expect(result.data.length).to.be(2);
expect(result.data.length).to.be(3);
expect(result.data[0].datapoints.length).to.be(2);
expect(result.data[0].target).to.be('server1 Count and!');
expect(result.data[1].target).to.be('server2 Count and!');
expect(result.data[0].target).to.be('server1 Count and {{not_exist}} server1');
expect(result.data[1].target).to.be('server2 Count and {{not_exist}} server2');
expect(result.data[2].target).to.be('0 Count and {{not_exist}} 0');
});
});