Skip to content

Commit

Permalink
Merge pull request #4 from shaharmor/patch-1
Browse files Browse the repository at this point in the history
Add support for normalized_value metric (Derivative)
isabek authored Dec 3, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 1f7e1cf + 2da659d commit 4242364
Showing 2 changed files with 58 additions and 3 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -97,8 +97,8 @@ function isSubAgg(subAgg) {
}

function handleMetrics(next, first, agg, metric, metricName, pastAggregation) {
if (!metric.hasOwnProperty("value")) return next(agg, metric, metricName, pastAggregation);
return agg.addMetric(metricName, metric.value);
if (!metric.hasOwnProperty("value") && !metric.hasOwnProperty("normalized_value")) return next(agg, metric, metricName, pastAggregation);
return agg.addMetric(metricName, metric.normalized_value || metric.value);
}

function handleOneBucket(next, first, agg, bucket, key, pastAggregation) {
57 changes: 56 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
@@ -57,6 +57,61 @@ describe("testing Elasticsearch Response Parser", function () {

done();
});

it("should prefer 'normalized_value' property of a metric over the 'value' property", function (done) {

var esResponse = {
"aggregations": {
"offerId": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "F1A2LqSYD3u",
"doc_count": 6,
"offerClick": {
"value": 6.0,
"normalized_value": 10.0
}
},
{
"key": "F1MGDprRRJP",
"doc_count": 6,
"offerClick": {
"value": 6.0,
"normalized_value": 15.0
}
},
{
"key": "F1MGDprnv7y",
"doc_count": 5,
"offerClick": {
"value": 5.0,
"normalized_value": 7.0
}
}
]
}
}
};

assert.deepEqual(esResponseParser.parse(esResponse), [
{
"offerClick": 10,
"offerId": "F1A2LqSYD3u"
},
{
"offerClick": 15,
"offerId": "F1MGDprRRJP"
},
{
"offerClick": 7,
"offerId": "F1MGDprnv7y"
}
]);

done();
});

it("should return parsed aggregation in object with 2 group by and 3 metric", function (done) {
var response = {
@@ -692,4 +747,4 @@ describe("testing Elasticsearch Response Parser", function () {
]);
done();
});
});
});

0 comments on commit 4242364

Please sign in to comment.