diff --git a/public/app/features/templating/editorCtrl.js b/public/app/features/templating/editorCtrl.js
index 524cc9f86fd..74157ac3dd8 100644
--- a/public/app/features/templating/editorCtrl.js
+++ b/public/app/features/templating/editorCtrl.js
@@ -36,6 +36,17 @@ function (angular, _) {
$scope.reset();
}
});
+
+ $scope.$watch('current.datasource', function(val) {
+ if ($scope.mode === 'new') {
+ datasourceSrv.get(val).then(function(ds) {
+ if (ds.meta.defaultMatchFormat) {
+ $scope.current.allFormat = ds.meta.defaultMatchFormat;
+ $scope.current.multiFormat = ds.meta.defaultMatchFormat;
+ }
+ });
+ }
+ });
};
$scope.add = function() {
diff --git a/public/app/features/templating/partials/editor.html b/public/app/features/templating/partials/editor.html
index ca304536849..a1dab0a6c36 100644
--- a/public/app/features/templating/partials/editor.html
+++ b/public/app/features/templating/partials/editor.html
@@ -186,7 +186,7 @@
All format
-
+
@@ -217,7 +217,7 @@
Multi format
-
+
diff --git a/public/app/features/templating/templateSrv.js b/public/app/features/templating/templateSrv.js
index b00fba9e71c..0880df1a0c4 100644
--- a/public/app/features/templating/templateSrv.js
+++ b/public/app/features/templating/templateSrv.js
@@ -39,10 +39,17 @@ function (angular, _) {
if (_.isString(value)) {
return value;
} else {
- if (variable.multiFormat === 'regex values') {
- return '(' + value.join('|') + ')';
+ switch(variable.multiFormat) {
+ case "regex values": {
+ return '(' + value.join('|') + ')';
+ }
+ case "lucene": {
+ return '(' + value.join(' OR ') + ')';
+ }
+ default: {
+ return '{' + value.join(',') + '}';
+ }
}
- return '{' + value.join(',') + '}';
}
};
diff --git a/public/app/features/templating/templateValuesSrv.js b/public/app/features/templating/templateValuesSrv.js
index 8c9404a32e6..a3300853065 100644
--- a/public/app/features/templating/templateValuesSrv.js
+++ b/public/app/features/templating/templateValuesSrv.js
@@ -253,21 +253,29 @@ function (angular, _, kbn) {
this.addAllOption = function(variable) {
var allValue = '';
switch(variable.allFormat) {
- case 'wildcard':
- allValue = '*';
- break;
- case 'regex wildcard':
- allValue = '.*';
- break;
- case 'regex values':
- allValue = '(' + _.map(variable.options, function(option) {
- return self.regexEscape(option.text);
- }).join('|') + ')';
- break;
- default:
- allValue = '{';
- allValue += _.pluck(variable.options, 'text').join(',');
- allValue += '}';
+ case 'wildcard': {
+ allValue = '*';
+ break;
+ }
+ case 'regex wildcard': {
+ allValue = '.*';
+ break;
+ }
+ case 'lucene': {
+ allValue = '(' + _.pluck(variable.options, 'text').join(' OR ') + ')';
+ break;
+ }
+ case 'regex values': {
+ allValue = '(' + _.map(variable.options, function(option) {
+ return self.regexEscape(option.text);
+ }).join('|') + ')';
+ break;
+ }
+ default: {
+ allValue = '{';
+ allValue += _.pluck(variable.options, 'text').join(',');
+ allValue += '}';
+ }
}
variable.options.unshift({text: 'All', value: allValue});
diff --git a/public/app/plugins/datasource/elasticsearch/datasource.js b/public/app/plugins/datasource/elasticsearch/datasource.js
index b8491309881..5f7d3860cf3 100644
--- a/public/app/plugins/datasource/elasticsearch/datasource.js
+++ b/public/app/plugins/datasource/elasticsearch/datasource.js
@@ -233,6 +233,9 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
ElasticDatasource.prototype.metricFindQuery = function(query) {
query = templateSrv.replace(query);
query = angular.fromJson(query);
+ if (!query) {
+ return $q.when([]);
+ }
if (query.find === 'fields') {
return this.getFields(query);
diff --git a/public/app/plugins/datasource/elasticsearch/plugin.json b/public/app/plugins/datasource/elasticsearch/plugin.json
index 92d6530635d..a0350bd8c6c 100644
--- a/public/app/plugins/datasource/elasticsearch/plugin.json
+++ b/public/app/plugins/datasource/elasticsearch/plugin.json
@@ -12,6 +12,7 @@
"annotations": "app/plugins/datasource/elasticsearch/partials/annotations.editor.html"
},
+ "defaultMatchFormat": "lucene",
"annotations": true,
"metrics": true
}
diff --git a/public/app/plugins/datasource/graphite/plugin.json b/public/app/plugins/datasource/graphite/plugin.json
index 318d8ee36d3..b170cc708f1 100644
--- a/public/app/plugins/datasource/graphite/plugin.json
+++ b/public/app/plugins/datasource/graphite/plugin.json
@@ -11,6 +11,7 @@
"config": "app/plugins/datasource/graphite/partials/config.html"
},
+ "defaultMatchFormat": "glob",
"metrics": true,
"annotations": true
}
diff --git a/public/app/plugins/datasource/influxdb/plugin.json b/public/app/plugins/datasource/influxdb/plugin.json
index aa235344972..d586d679367 100644
--- a/public/app/plugins/datasource/influxdb/plugin.json
+++ b/public/app/plugins/datasource/influxdb/plugin.json
@@ -11,6 +11,7 @@
"config": "app/plugins/datasource/influxdb/partials/config.html"
},
+ "defaultMatchFormat": "regex values",
"metrics": true,
"annotations": true
}
diff --git a/public/app/plugins/datasource/influxdb_08/plugin.json b/public/app/plugins/datasource/influxdb_08/plugin.json
index 72d392ca808..975b2cceaf4 100644
--- a/public/app/plugins/datasource/influxdb_08/plugin.json
+++ b/public/app/plugins/datasource/influxdb_08/plugin.json
@@ -11,6 +11,7 @@
"config": "app/plugins/datasource/influxdb_08/partials/config.html"
},
+ "defaultMatchFormat": "regex values",
"metrics": true,
"annotations": true
}
diff --git a/public/test/specs/templateSrv-specs.js b/public/test/specs/templateSrv-specs.js
index fbca645ce67..1b43adff63e 100644
--- a/public/test/specs/templateSrv-specs.js
+++ b/public/test/specs/templateSrv-specs.js
@@ -61,6 +61,16 @@ define([
expect(result).to.be('{test,test2}');
});
+ it('multi value and lucene should render as lucene expr', function() {
+ var result = _templateSrv.renderVariableValue({
+ multiFormat: 'lucene',
+ current: {
+ value: ['test','test2'],
+ }
+ });
+ expect(result).to.be('(test OR test2)');
+ });
+
it('multi value and regex format should render regex string', function() {
var result = _templateSrv.renderVariableValue({
multiFormat: 'regex values',
diff --git a/public/test/specs/templateValuesSrv-specs.js b/public/test/specs/templateValuesSrv-specs.js
index ecbd3a2e682..feb13c37130 100644
--- a/public/test/specs/templateValuesSrv-specs.js
+++ b/public/test/specs/templateValuesSrv-specs.js
@@ -314,6 +314,17 @@ define([
});
});
+ describeUpdateVariable('with include all lucene and values', function(scenario) {
+ scenario.setup(function() {
+ scenario.variable = { type: 'query', query: 'apps.*', name: 'test', includeAll: true, allFormat: 'lucene' };
+ scenario.queryResult = [{text: 'backend1'}, { text: 'backend2'}];
+ });
+
+ it('should add lucene glob', function() {
+ expect(scenario.variable.options[0].value).to.be('(backend1 OR backend2)');
+ });
+ });
+
describeUpdateVariable('with include all regex all values', function(scenario) {
scenario.setup(function() {
scenario.variable = { type: 'query', query: 'apps.*', name: 'test', includeAll: true, allFormat: 'regex values' };