mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 16:15:42 -06:00
fix: elasticsearch with template variable with terms agg on IP field, fixes #8662
This commit is contained in:
parent
4844bf9be3
commit
e4950c2dc1
@ -323,26 +323,27 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
|
|||||||
|
|
||||||
var buckets = res.responses[0].aggregations["1"].buckets;
|
var buckets = res.responses[0].aggregations["1"].buckets;
|
||||||
return _.map(buckets, function(bucket) {
|
return _.map(buckets, function(bucket) {
|
||||||
return {text: bucket.key, value: bucket.key};
|
return {
|
||||||
|
text: bucket.key_as_string || bucket.key,
|
||||||
|
value: bucket.key
|
||||||
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.metricFindQuery = function(query) {
|
this.metricFindQuery = function(query) {
|
||||||
query = angular.fromJson(query);
|
query = angular.fromJson(query);
|
||||||
query.query = templateSrv.replace(query.query || '*', {}, 'lucene');
|
|
||||||
if ('field' in query) {
|
|
||||||
query.field = templateSrv.replace(query.field, {}, 'lucene');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
return $q.when([]);
|
return $q.when([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.find === 'fields') {
|
if (query.find === 'fields') {
|
||||||
|
query.field = templateSrv.replace(query.field, {}, 'lucene');
|
||||||
return this.getFields(query);
|
return this.getFields(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.find === 'terms') {
|
if (query.find === 'terms') {
|
||||||
|
query.query = templateSrv.replace(query.query || '*', {}, 'lucene');
|
||||||
return this.getTerms(query);
|
return this.getTerms(query);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -248,7 +248,7 @@ describe('ElasticDatasource', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('When issuing metricFind query on es5.x', function() {
|
describe('When issuing metricFind query on es5.x', function() {
|
||||||
var requestOptions, parts, header, body;
|
var requestOptions, parts, header, body, results;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
createDatasource({url: 'http://es.com', index: 'test', jsonData: {esVersion: '5'}});
|
createDatasource({url: 'http://es.com', index: 'test', jsonData: {esVersion: '5'}});
|
||||||
@ -257,12 +257,26 @@ describe('ElasticDatasource', function() {
|
|||||||
requestOptions = options;
|
requestOptions = options;
|
||||||
return ctx.$q.when({
|
return ctx.$q.when({
|
||||||
data: {
|
data: {
|
||||||
responses: [{aggregations: {"1": [{buckets: {text: 'test', value: '1'}}]}}]
|
responses: [
|
||||||
|
{
|
||||||
|
aggregations: {
|
||||||
|
"1": {
|
||||||
|
buckets: [
|
||||||
|
{doc_count: 1, key: 'test'},
|
||||||
|
{doc_count: 2, key: 'test2', key_as_string: 'test2_as_string'},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
ctx.ds.metricFindQuery('{"find": "terms", "field": "test"}');
|
ctx.ds.metricFindQuery('{"find": "terms", "field": "test"}').then(res => {
|
||||||
|
results = res;
|
||||||
|
});
|
||||||
|
|
||||||
ctx.$rootScope.$apply();
|
ctx.$rootScope.$apply();
|
||||||
|
|
||||||
parts = requestOptions.data.split('\n');
|
parts = requestOptions.data.split('\n');
|
||||||
@ -270,6 +284,15 @@ describe('ElasticDatasource', function() {
|
|||||||
body = angular.fromJson(parts[1]);
|
body = angular.fromJson(parts[1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should get results', function() {
|
||||||
|
expect(results.length).to.eql(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use key or key_as_string', function() {
|
||||||
|
expect(results[0].text).to.eql('test');
|
||||||
|
expect(results[1].text).to.eql('test2_as_string');
|
||||||
|
});
|
||||||
|
|
||||||
it('should not set search type to count', function() {
|
it('should not set search type to count', function() {
|
||||||
expect(header.search_type).to.not.eql('count');
|
expect(header.search_type).to.not.eql('count');
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user