diff --git a/public/app/plugins/datasource/elasticsearch/elastic_response.js b/public/app/plugins/datasource/elasticsearch/elastic_response.js
index 1994102bc82..fd53873aa8d 100644
--- a/public/app/plugins/datasource/elasticsearch/elastic_response.js
+++ b/public/app/plugins/datasource/elasticsearch/elastic_response.js
@@ -199,7 +199,11 @@ function (_, queryDef) {
if (series.field && series.metric === 'moving_avg') {
var appliedAgg = _.findWhere(target.metrics, { id: series.field });
- metricName += ' ' + queryDef.describeMetric(appliedAgg);
+ if (appliedAgg) {
+ metricName += ' ' + queryDef.describeMetric(appliedAgg);
+ } else {
+ metricName = 'Unset';
+ }
} else if (series.field) {
metricName += ' ' + series.field;
}
diff --git a/public/app/plugins/datasource/elasticsearch/metric_agg.js b/public/app/plugins/datasource/elasticsearch/metric_agg.js
index 149623bdd9b..1d6f82a292f 100644
--- a/public/app/plugins/datasource/elasticsearch/metric_agg.js
+++ b/public/app/plugins/datasource/elasticsearch/metric_agg.js
@@ -22,7 +22,7 @@ function (angular, _, queryDef) {
};
$scope.updateMavgOptions = function() {
- $scope.mavgOptions = queryDef.getMovingAverageSourceOptions($scope.target);
+ $scope.mavgOptions = queryDef.getMovingAverageOptions($scope.target);
};
$rootScope.onAppEvent('elastic-query-updated', function() {
@@ -43,9 +43,9 @@ function (angular, _, queryDef) {
switch($scope.agg.type) {
case 'moving_avg': {
- $scope.agg.mavgSource = $scope.agg.mavgSource || 'Metric to apply moving average';
+ $scope.agg.pipelineAgg = $scope.agg.pipelineAgg || 'Metric to apply moving average';
$scope.settingsLinkText = 'Moving average options';
- $scope.agg.field = $scope.agg.mavgSource;
+ $scope.agg.field = $scope.agg.pipelineAgg;
break;
}
case 'percentiles': {
diff --git a/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html b/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html
index 3ddec210ceb..7c21e64721e 100644
--- a/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html
+++ b/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html
@@ -33,7 +33,7 @@
Based on
-
+
diff --git a/public/app/plugins/datasource/elasticsearch/query_builder.js b/public/app/plugins/datasource/elasticsearch/query_builder.js
index 967f8851495..64128943f40 100644
--- a/public/app/plugins/datasource/elasticsearch/query_builder.js
+++ b/public/app/plugins/datasource/elasticsearch/query_builder.js
@@ -171,8 +171,8 @@ function () {
var metricAgg = null;
if (metric.type === 'moving_avg') {
- if (metric.mavgSource && /^\d*$/.test(metric.mavgSource)) {
- metricAgg = { buckets_path: metric.mavgSource };
+ if (metric.pipelineAgg && /^\d*$/.test(metric.pipelineAgg)) {
+ metricAgg = { buckets_path: metric.pipelineAgg };
} else {
continue;
}
diff --git a/public/app/plugins/datasource/elasticsearch/query_def.js b/public/app/plugins/datasource/elasticsearch/query_def.js
index 885704c4d25..6fed5580576 100644
--- a/public/app/plugins/datasource/elasticsearch/query_def.js
+++ b/public/app/plugins/datasource/elasticsearch/query_def.js
@@ -67,7 +67,17 @@ function (_) {
{text: '1d', value: '1d'},
],
- getMovingAverageSourceOptions: function(targets) {
+ pipelineAggs: ['moving_avg'],
+
+ isPipelineAgg: function(metric) {
+ if (metric.type) {
+ return this.pipelineAggs.indexOf(metric.type) > -1;
+ }
+
+ return false;
+ },
+
+ getMovingAverageOptions: function(targets) {
var self = this;
var result = [];
_.each(targets.metrics, function(metric) {
diff --git a/public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts b/public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts
index 3c2c52916cb..91cdba7248e 100644
--- a/public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts
+++ b/public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts
@@ -167,7 +167,7 @@ describe('ElasticQueryBuilder', function() {
id: '2',
type: 'moving_avg',
field: '3',
- mavgSource: '3'
+ pipelineAgg: '3'
}
],
bucketAggs: [
@@ -194,13 +194,13 @@ describe('ElasticQueryBuilder', function() {
id: '2',
type: 'moving_avg',
field: '3',
- mavgSource: '3'
+ pipelineAgg: '3'
},
{
id: '4',
type: 'moving_avg',
field: '3',
- mavgSource: 'Metric to apply moving average'
+ pipelineAgg: 'Metric to apply moving average'
}
],
bucketAggs: [
diff --git a/public/app/plugins/datasource/elasticsearch/specs/query_def_specs.ts b/public/app/plugins/datasource/elasticsearch/specs/query_def_specs.ts
index 18d22f794d5..cf375430ae1 100644
--- a/public/app/plugins/datasource/elasticsearch/specs/query_def_specs.ts
+++ b/public/app/plugins/datasource/elasticsearch/specs/query_def_specs.ts
@@ -8,41 +8,61 @@ declare var QueryDef: any;
describe('ElasticQueryDef', function() {
- describe('with zero targets', function() {
- var response = QueryDef.getMovingAverageSourceOptions([]);
+ describe('getMovingAverageOptions', function() {
+ describe('with zero targets', function() {
+ var response = QueryDef.getMovingAverageOptions([]);
- it('should return zero', function() {
- expect(response.length).to.be(0);
+ it('should return zero', function() {
+ expect(response.length).to.be(0);
+ });
+ });
+
+ describe('with count and sum targets', function() {
+ var targets = {
+ metrics: [
+ { type: 'count', field: '@value' },
+ { type: 'sum', field: '@value' }
+ ]
+ };
+
+ var response = QueryDef.getMovingAverageOptions(targets);
+
+ it('should return zero', function() {
+ expect(response.length).to.be(2);
+ });
+ });
+
+ describe('with count and moving average targets', function() {
+ var targets = {
+ metrics: [
+ { type: 'count', field: '@value' },
+ { type: 'moving_avg', field: '@value' }
+ ]
+ };
+
+ var response = QueryDef.getMovingAverageOptions(targets);
+
+ it('should return zero', function() {
+ expect(response.length).to.be(1);
+ });
});
});
- describe('with count and sum targets', function() {
- var targets = {
- metrics: [
- { type: 'count', field: '@value' },
- { type: 'sum', field: '@value' }
- ]
- };
+ describe('isPipelineMetric', function() {
+ describe('moving_avg', function() {
+ var result = QueryDef.isPipelineAgg({ type: 'moving_avg' });
- var response = QueryDef.getMovingAverageSourceOptions(targets);
-
- it('should return zero', function() {
- expect(response.length).to.be(2);
+ it('is pipe line metric', function() {
+ expect(result).to.be(true);
+ });
});
- });
- describe('with count and moving average targets', function() {
- var targets = {
- metrics: [
- { type: 'count', field: '@value' },
- { type: 'moving_avg', field: '@value' }
- ]
- };
+ describe('count', function() {
+ var result = QueryDef.isPipelineAgg({ type: 'count' });
- var response = QueryDef.getMovingAverageSourceOptions(targets);
-
- it('should return zero', function() {
- expect(response.length).to.be(1);
+ it('is not pipe line metric', function() {
+ expect(result).to.be(false);
+ });
});
});
});