mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
feat(elasticsearch): term metric filters are starting to work! like terms aggregation with top 5, order by metric 1 desc, where metric 1 is maybe average of @load
This commit is contained in:
parent
f1e995ec79
commit
2d832e10b0
@ -65,7 +65,7 @@ function (angular, _, $) {
|
||||
$scope.orderByOptions = [
|
||||
{text: "Doc Count", value: '_count' },
|
||||
{text: "Term name", value: '_term' },
|
||||
{text: "Average of @value", value: 'm0' },
|
||||
{text: "Average of @value", value: '1' },
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ function (angular) {
|
||||
return angular.fromJson(target.rawQuery);
|
||||
}
|
||||
|
||||
var i, nestedAggs;
|
||||
var i, y, nestedAggs, metric, metricRef;
|
||||
var query = {
|
||||
"size": 0,
|
||||
"query": {
|
||||
@ -57,15 +57,29 @@ function (angular) {
|
||||
esAgg.terms = { "field": aggDef.field };
|
||||
var size = parseInt(aggDef.size, 10);
|
||||
if (size > 0) { esAgg.terms.size = size; }
|
||||
if (aggDef.orderBy) {
|
||||
if (aggDef.orderBy != void 0) {
|
||||
esAgg.terms.order = {};
|
||||
esAgg.terms.order[aggDef.orderBy] = aggDef.order;
|
||||
|
||||
// if metric ref, look it up and add it to this agg level
|
||||
metricRef = parseInt(aggDef.orderBy, 10);
|
||||
if (!isNaN(metricRef)) {
|
||||
for (y = 0; y < target.metrics.length; y++) {
|
||||
metric = target.metrics[y];
|
||||
if (metric.id === aggDef.orderBy) {
|
||||
esAgg.aggs = {};
|
||||
esAgg.aggs[metric.id] = {}
|
||||
esAgg.aggs[metric.id][metric.type] = {field: metric.field};
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
nestedAggs.aggs = {};
|
||||
nestedAggs.aggs = nestedAggs.aggs || {};
|
||||
nestedAggs.aggs[aggDef.id] = esAgg;
|
||||
nestedAggs = esAgg;
|
||||
}
|
||||
@ -73,7 +87,7 @@ function (angular) {
|
||||
nestedAggs.aggs = {};
|
||||
|
||||
for (i = 0; i < target.metrics.length; i++) {
|
||||
var metric = target.metrics[i];
|
||||
metric = target.metrics[i];
|
||||
if (metric.type === 'count') {
|
||||
continue;
|
||||
}
|
||||
|
@ -51,9 +51,9 @@ define([
|
||||
var builder = new ElasticQueryBuilder();
|
||||
|
||||
var query = builder.build({
|
||||
metrics: [{type: 'avg', field: '@value', id: '1'}],
|
||||
metrics: [{type: 'count', id: '1'}, {type: 'avg', field: '@value', id: '5'}],
|
||||
bucketAggs: [
|
||||
{type: 'term', size: 5, order: 'asc', orderBy: 'm0', id: '2' },
|
||||
{type: 'terms', field: '@host', size: 5, order: 'asc', orderBy: '5', id: '2' },
|
||||
{type: 'date_histogram', field: '@timestamp', id: '3'}
|
||||
],
|
||||
}, 100, 1000);
|
||||
@ -61,8 +61,8 @@ define([
|
||||
var firstLevel = query.aggs["2"];
|
||||
var secondLevel = firstLevel.aggs["3"];
|
||||
|
||||
// expect(firstLevel.aggs["m0"].avg.field).to.be("@value");
|
||||
expect(secondLevel.aggs["1"].avg.field).to.be("@value");
|
||||
expect(firstLevel.aggs["5"].avg.field).to.be("@value");
|
||||
expect(secondLevel.aggs["5"].avg.field).to.be("@value");
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user