diff --git a/public/app/plugins/datasource/elasticsearch/elasticResponse.js b/public/app/plugins/datasource/elasticsearch/elasticResponse.js
index b6dd4254ea0..f0370c6f688 100644
--- a/public/app/plugins/datasource/elasticsearch/elasticResponse.js
+++ b/public/app/plugins/datasource/elasticsearch/elasticResponse.js
@@ -1,7 +1,8 @@
define([
- "lodash"
+ "lodash",
+ "./queryDef"
],
-function (_) {
+function (_, queryDef) {
'use strict';
function ElasticResponse(targets, response) {
@@ -87,7 +88,7 @@ function (_) {
break;
}
default: {
- newSeries = { datapoints: [], metric: metric.type + ' ' + metric.field, props: props};
+ 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;
@@ -100,35 +101,62 @@ function (_) {
}
};
- ElasticResponse.prototype._getSeriesName = function(props, metric, target, metricTypeCount) {
+ ElasticResponse.prototype._getMetricName = function(metric) {
+ var metricDef = _.findWhere(queryDef.metricAggTypes, {value: metric});
+ if (!metricDef) {
+ metricDef = _.findWhere(queryDef.extendedStats, {value: metric});
+ }
+
+ return metricDef ? metricDef.text : metric;
+ };
+
+ ElasticResponse.prototype._getSeriesName = function(series, target, metricTypeCount) {
+ var metricName = this._getMetricName(series.metric);
+
if (target.alias) {
var regex = /\{\{([\s\S]+?)\}\}/g;
return target.alias.replace(regex, function(match, g1, g2) {
var group = g1 || g2;
- if (props[group]) { return props[group]; }
- if (group === 'metric') { return metric; }
+ if (group.indexOf('term ') === 0) { return series.props[group.substring(5)]; }
+ if (series.props[group]) { return series.props[group]; }
+ if (group === 'metric') { return metricName; }
+ if (group === 'field') { return series.field; }
return match;
});
}
- var propKeys = _.keys(props);
+ if (series.field) {
+ metricName += ' ' + series.field;
+ }
+
+ var propKeys = _.keys(series.props);
if (propKeys.length === 0) {
- return metric;
+ return metricName;
}
var name = '';
- for (var propName in props) {
- name += props[propName] + ' ';
+ for (var propName in series.props) {
+ name += series.props[propName] + ' ';
}
if (metricTypeCount === 1) {
return name.trim();
}
- return name.trim() + ' ' + metric;
+ return name.trim() + ' ' + metricName;
+ };
+
+ ElasticResponse.prototype.nameSeries = function(seriesList, target) {
+ var metricTypeCount = _.uniq(_.pluck(seriesList, 'metric')).length;
+ var fieldNameCount = _.uniq(_.pluck(seriesList, 'field')).length;
+
+ for (var i = 0; i < seriesList.length; i++) {
+ var series = seriesList[i];
+ series.target = this._getSeriesName(series, target, metricTypeCount, fieldNameCount);
+ }
};
ElasticResponse.prototype.getTimeSeries = function() {
@@ -145,13 +173,10 @@ function (_) {
var tmpSeriesList = [];
this.processBuckets(aggregations, target, tmpSeriesList, 0, {});
-
- var metricTypeCount = _.uniq(_.pluck(tmpSeriesList, 'metric')).length;
+ this.nameSeries(tmpSeriesList, target);
for (var y = 0; y < tmpSeriesList.length; y++) {
- var series= tmpSeriesList[y];
- series.target = this._getSeriesName(series.props, series.metric, target, metricTypeCount);
- seriesList.push(series);
+ seriesList.push(tmpSeriesList[y]);
}
}
diff --git a/public/app/plugins/datasource/elasticsearch/metricAgg.js b/public/app/plugins/datasource/elasticsearch/metricAgg.js
index bfa265cfc26..26a0323013f 100644
--- a/public/app/plugins/datasource/elasticsearch/metricAgg.js
+++ b/public/app/plugins/datasource/elasticsearch/metricAgg.js
@@ -48,6 +48,11 @@ function (angular, _, queryDef) {
return memo;
}, []);
$scope.settingsLinkText = 'Stats: ' + stats.join(', ');
+
+ if (stats.length === 0) {
+ $scope.agg.meta.std_deviation_bounds_lower = true;
+ $scope.agg.meta.std_deviation_bounds_upper = true;
+ }
}
}
};
diff --git a/public/app/plugins/datasource/elasticsearch/partials/query.editor.html b/public/app/plugins/datasource/elasticsearch/partials/query.editor.html
index ccbe846a7fd..20566e6f4d3 100644
--- a/public/app/plugins/datasource/elasticsearch/partials/query.editor.html
+++ b/public/app/plugins/datasource/elasticsearch/partials/query.editor.html
@@ -51,7 +51,7 @@
Alias
-
+
diff --git a/public/app/plugins/datasource/elasticsearch/partials/query.options.html b/public/app/plugins/datasource/elasticsearch/partials/query.options.html
index c56eea6d34d..f7eb67e52d3 100644
--- a/public/app/plugins/datasource/elasticsearch/partials/query.options.html
+++ b/public/app/plugins/datasource/elasticsearch/partials/query.options.html
@@ -19,11 +19,10 @@
Alias patterns
-
- - $m = replaced with measurement name
- - $measurement = replaced with measurement name
- - $tag_hostname = replaced with the value of the hostname tag
- - You can also use [[tag_hostname]] pattern replacement syntax
+
+ - {{term fieldname}} = replaced with value of term group by
+ - {{metric}} = replaced with metric name (ex. Average, Min, Max)
+ - {{field}} = replaced with the metric field name
diff --git a/public/app/plugins/datasource/elasticsearch/queryDef.js b/public/app/plugins/datasource/elasticsearch/queryDef.js
index 1925c7373f3..8770ea25fba 100644
--- a/public/app/plugins/datasource/elasticsearch/queryDef.js
+++ b/public/app/plugins/datasource/elasticsearch/queryDef.js
@@ -7,10 +7,10 @@ function (_) {
return {
metricAggTypes: [
{text: "Count", value: 'count' },
- {text: "Average of", value: 'avg' },
- {text: "Sum of", value: 'sum' },
- {text: "Max of", value: 'max' },
- {text: "Min of", value: 'min' },
+ {text: "Average", value: 'avg' },
+ {text: "Sum", value: 'sum' },
+ {text: "Max", value: 'max' },
+ {text: "Min", value: 'min' },
{text: "Extended Stats", value: 'extended_stats' },
{text: "Percentiles", value: 'percentiles' },
{text: "Unique Count", value: "cardinality" }
diff --git a/public/test/specs/elasticsearch-response-specs.js b/public/test/specs/elasticsearch-response-specs.js
index e314a88ba88..0f2603d324f 100644
--- a/public/test/specs/elasticsearch-response-specs.js
+++ b/public/test/specs/elasticsearch-response-specs.js
@@ -40,7 +40,7 @@ define([
it('should return 1 series', function() {
expect(result.data.length).to.be(1);
- expect(result.data[0].target).to.be('count');
+ expect(result.data[0].target).to.be('Count');
expect(result.data[0].datapoints.length).to.be(2);
expect(result.data[0].datapoints[0][0]).to.be(10);
expect(result.data[0].datapoints[0][1]).to.be(1000);
@@ -87,7 +87,7 @@ define([
expect(result.data[0].datapoints[0][0]).to.be(10);
expect(result.data[0].datapoints[0][1]).to.be(1000);
- expect(result.data[1].target).to.be("avg value");
+ expect(result.data[1].target).to.be("Average value");
expect(result.data[1].datapoints[0][0]).to.be(88);
expect(result.data[1].datapoints[1][0]).to.be(99);
});
@@ -191,10 +191,10 @@ define([
it('should return 2 series', function() {
expect(result.data.length).to.be(4);
expect(result.data[0].datapoints.length).to.be(2);
- expect(result.data[0].target).to.be('server1 count');
- expect(result.data[1].target).to.be('server1 avg @value');
- expect(result.data[2].target).to.be('server2 count');
- expect(result.data[3].target).to.be('server2 avg @value');
+ expect(result.data[0].target).to.be('server1 Count');
+ expect(result.data[1].target).to.be('server1 Average @value');
+ expect(result.data[2].target).to.be('server2 Count');
+ expect(result.data[3].target).to.be('server2 Average @value');
});
});
@@ -288,8 +288,8 @@ define([
it('should return 4 series', function() {
expect(result.data.length).to.be(4);
expect(result.data[0].datapoints.length).to.be(1);
- expect(result.data[0].target).to.be('server1 max');
- expect(result.data[1].target).to.be('server1 std_deviation_bounds_upper');
+ expect(result.data[0].target).to.be('server1 Max');
+ expect(result.data[1].target).to.be('server1 Std Dev Upper');
expect(result.data[0].datapoints[0][0]).to.be(10.2);
expect(result.data[1].datapoints[0][0]).to.be(3);
@@ -303,7 +303,7 @@ define([
targets = [{
refId: 'A',
metrics: [{type: 'count', id: '1'}],
- alias: '{{@host}} {{metric}} and!',
+ alias: '{{term @host}} {{metric}} and!',
bucketAggs: [
{type: 'terms', field: '@host', id: '2'},
{type: 'date_histogram', field: '@timestamp', id: '3'}
@@ -346,8 +346,8 @@ define([
it('should return 2 series', function() {
expect(result.data.length).to.be(2);
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!');
+ expect(result.data[1].target).to.be('server2 Count and!');
});
});