diff --git a/public/app/plugins/datasource/elasticsearch/elastic_response.js b/public/app/plugins/datasource/elasticsearch/elastic_response.js index 73050ce7f2b..a7c8e6d14bf 100644 --- a/public/app/plugins/datasource/elasticsearch/elastic_response.js +++ b/public/app/plugins/datasource/elasticsearch/elastic_response.js @@ -76,8 +76,12 @@ function (_, queryDef) { newSeries = { datapoints: [], metric: metric.type, field: metric.field, props: props}; for (i = 0; i < esAgg.buckets.length; i++) { bucket = esAgg.buckets[i]; - value = bucket[metric.id].value; - newSeries.datapoints.push([value, bucket.key]); + + value = bucket[metric.id]; + if (value !== undefined) { + newSeries.datapoints.push([value.value, bucket.key]); + } + } seriesList.push(newSeries); break; diff --git a/public/app/plugins/datasource/elasticsearch/metric_agg.js b/public/app/plugins/datasource/elasticsearch/metric_agg.js index 6e149e91384..157ee95a6c4 100644 --- a/public/app/plugins/datasource/elasticsearch/metric_agg.js +++ b/public/app/plugins/datasource/elasticsearch/metric_agg.js @@ -13,7 +13,6 @@ function (angular, _, queryDef) { $scope.metricAggTypes = queryDef.metricAggTypes; $scope.extendedStats = queryDef.extendedStats; - $scope.mavgSourceOptions = []; $scope.init = function() { $scope.agg = metricAggs[$scope.index]; @@ -23,7 +22,6 @@ function (angular, _, queryDef) { $rootScope.onAppEvent('elastic-query-updated', function() { $scope.index = _.indexOf(metricAggs, $scope.agg); $scope.validateModel(); - $scope.updateMovingAverageOptions(); }, $scope); $scope.validateModel = function() { @@ -38,7 +36,7 @@ function (angular, _, queryDef) { switch($scope.agg.type) { case 'moving_avg': { - $scope.agg.mavgSource = $scope.agg.mavgSource || ''; + $scope.agg.mavgSource = $scope.agg.mavgSource || 'Basec on metric'; $scope.settingsLinkText = 'Moving average options'; break; } @@ -90,6 +88,11 @@ function (angular, _, queryDef) { return $scope.getFields({$fieldType: 'number'}); }; + $scope.mavgSourceOptions = function() { + return $q.when(queryDef.getMovingAverageSourceOptions($scope.target)) + .then(uiSegmentSrv.transformToSegments(false)); + }; + $scope.addMetricAgg = function() { var addIndex = metricAggs.length; @@ -101,10 +104,6 @@ function (angular, _, queryDef) { $scope.onChange(); }; - $scope.updateMovingAverageOptions = function() { - $scope.mvagSourceOptions = queryDef.getMovingAverageSourceOptions($scope.target); - }; - $scope.removeMetricAgg = function() { metricAggs.splice($scope.index, 1); $scope.onChange(); diff --git a/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html b/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html index 2e34b28612d..e7f726c1616 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_def.js b/public/app/plugins/datasource/elasticsearch/query_def.js index 865c74753b3..885704c4d25 100644 --- a/public/app/plugins/datasource/elasticsearch/query_def.js +++ b/public/app/plugins/datasource/elasticsearch/query_def.js @@ -13,7 +13,7 @@ function (_) { {text: "Min", value: 'min', requiresField: true}, {text: "Extended Stats", value: 'extended_stats', requiresField: true}, {text: "Percentiles", value: 'percentiles', requiresField: true}, - {text: "Moving Avg", value: 'moving_avg', requiresField: false }, + {text: "Moving Average", value: 'moving_avg', requiresField: false }, {text: "Unique Count", value: "cardinality", requiresField: true}, {text: "Raw Document", value: "raw_document", requiresField: false} ],