Commit 07310643 by Carl Bergquist

adds support for moving avg support in es queries

parent e1944614
......@@ -175,8 +175,28 @@ function () {
}
var aggField = {};
aggField[metric.type] = metricAgg;
nestedAggs.aggs[metric.id] = aggField;
if (metric.type === 'moving_avg') {
var pipeAgg = '';
for(var aggname in nestedAggs.aggs) {
var agg = nestedAggs.aggs[aggname];
for(prop in agg) {
if (agg.hasOwnProperty(prop) && agg[prop] !== null) {
if (metric.field === prop) {
pipeAgg = aggname;
break;
}
}
}
}
if (pipeAgg !== '') {
aggField[metric.type] = { buckets_path: pipeAgg };
nestedAggs.aggs[metric.id] = aggField;
}
} else {
aggField[metric.type] = metricAgg;
nestedAggs.aggs[metric.id] = aggField;
}
}
return query;
......@@ -217,5 +237,4 @@ function () {
};
return ElasticQueryBuilder;
});
......@@ -155,4 +155,28 @@ describe('ElasticQueryBuilder', function() {
expect(query.size).to.be(500);
});
it('with moving average', function() {
var query = builder.build({
metrics: [
{
id: '1',
type: 'sum',
field: '@value',
},
{
id: '2',
type: 'moving_avg',
field: 'sum'
}
],
bucketAggs: [
{type: 'date_histogram', field: '@timestamp', id: '3'}
],
});
var firstLevel = query.aggs["3"];
expect(firstLevel.aggs["2"]).not.to.be(undefined);
expect(firstLevel.aggs["2"].moving_avg).not.to.be(undefined);
expect(firstLevel.aggs["2"].moving_avg.buckets_path).to.be("1");
});
});
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