Commit 2d832e10 by Torkel Ödegaard

feat(elasticsearch): term metric filters are starting to work! like terms…

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
parent f1e995ec
...@@ -65,7 +65,7 @@ function (angular, _, $) { ...@@ -65,7 +65,7 @@ function (angular, _, $) {
$scope.orderByOptions = [ $scope.orderByOptions = [
{text: "Doc Count", value: '_count' }, {text: "Doc Count", value: '_count' },
{text: "Term name", value: '_term' }, {text: "Term name", value: '_term' },
{text: "Average of @value", value: 'm0' }, {text: "Average of @value", value: '1' },
]; ];
} }
......
...@@ -17,7 +17,7 @@ function (angular) { ...@@ -17,7 +17,7 @@ function (angular) {
return angular.fromJson(target.rawQuery); return angular.fromJson(target.rawQuery);
} }
var i, nestedAggs; var i, y, nestedAggs, metric, metricRef;
var query = { var query = {
"size": 0, "size": 0,
"query": { "query": {
...@@ -57,15 +57,29 @@ function (angular) { ...@@ -57,15 +57,29 @@ function (angular) {
esAgg.terms = { "field": aggDef.field }; esAgg.terms = { "field": aggDef.field };
var size = parseInt(aggDef.size, 10); var size = parseInt(aggDef.size, 10);
if (size > 0) { esAgg.terms.size = size; } if (size > 0) { esAgg.terms.size = size; }
if (aggDef.orderBy) { if (aggDef.orderBy != void 0) {
esAgg.terms.order = {}; esAgg.terms.order = {};
esAgg.terms.order[aggDef.orderBy] = aggDef.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; break;
} }
} }
nestedAggs.aggs = {}; nestedAggs.aggs = nestedAggs.aggs || {};
nestedAggs.aggs[aggDef.id] = esAgg; nestedAggs.aggs[aggDef.id] = esAgg;
nestedAggs = esAgg; nestedAggs = esAgg;
} }
...@@ -73,7 +87,7 @@ function (angular) { ...@@ -73,7 +87,7 @@ function (angular) {
nestedAggs.aggs = {}; nestedAggs.aggs = {};
for (i = 0; i < target.metrics.length; i++) { for (i = 0; i < target.metrics.length; i++) {
var metric = target.metrics[i]; metric = target.metrics[i];
if (metric.type === 'count') { if (metric.type === 'count') {
continue; continue;
} }
......
...@@ -51,9 +51,9 @@ define([ ...@@ -51,9 +51,9 @@ define([
var builder = new ElasticQueryBuilder(); var builder = new ElasticQueryBuilder();
var query = builder.build({ var query = builder.build({
metrics: [{type: 'avg', field: '@value', id: '1'}], metrics: [{type: 'count', id: '1'}, {type: 'avg', field: '@value', id: '5'}],
bucketAggs: [ 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'} {type: 'date_histogram', field: '@timestamp', id: '3'}
], ],
}, 100, 1000); }, 100, 1000);
...@@ -61,8 +61,8 @@ define([ ...@@ -61,8 +61,8 @@ define([
var firstLevel = query.aggs["2"]; var firstLevel = query.aggs["2"];
var secondLevel = firstLevel.aggs["3"]; var secondLevel = firstLevel.aggs["3"];
// expect(firstLevel.aggs["m0"].avg.field).to.be("@value"); expect(firstLevel.aggs["5"].avg.field).to.be("@value");
expect(secondLevel.aggs["1"].avg.field).to.be("@value"); expect(secondLevel.aggs["5"].avg.field).to.be("@value");
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment