Skip to content

Commit 4242364

Browse files
authored
Merge pull request #4 from shaharmor/patch-1
Add support for normalized_value metric (Derivative)
2 parents 1f7e1cf + 2da659d commit 4242364

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ function isSubAgg(subAgg) {
9797
}
9898

9999
function handleMetrics(next, first, agg, metric, metricName, pastAggregation) {
100-
if (!metric.hasOwnProperty("value")) return next(agg, metric, metricName, pastAggregation);
101-
return agg.addMetric(metricName, metric.value);
100+
if (!metric.hasOwnProperty("value") && !metric.hasOwnProperty("normalized_value")) return next(agg, metric, metricName, pastAggregation);
101+
return agg.addMetric(metricName, metric.normalized_value || metric.value);
102102
}
103103

104104
function handleOneBucket(next, first, agg, bucket, key, pastAggregation) {

test/index.test.js

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,61 @@ describe("testing Elasticsearch Response Parser", function () {
5757

5858
done();
5959
});
60+
61+
it("should prefer 'normalized_value' property of a metric over the 'value' property", function (done) {
62+
63+
var esResponse = {
64+
"aggregations": {
65+
"offerId": {
66+
"doc_count_error_upper_bound": 0,
67+
"sum_other_doc_count": 0,
68+
"buckets": [
69+
{
70+
"key": "F1A2LqSYD3u",
71+
"doc_count": 6,
72+
"offerClick": {
73+
"value": 6.0,
74+
"normalized_value": 10.0
75+
}
76+
},
77+
{
78+
"key": "F1MGDprRRJP",
79+
"doc_count": 6,
80+
"offerClick": {
81+
"value": 6.0,
82+
"normalized_value": 15.0
83+
}
84+
},
85+
{
86+
"key": "F1MGDprnv7y",
87+
"doc_count": 5,
88+
"offerClick": {
89+
"value": 5.0,
90+
"normalized_value": 7.0
91+
}
92+
}
93+
]
94+
}
95+
}
96+
};
97+
98+
assert.deepEqual(esResponseParser.parse(esResponse), [
99+
{
100+
"offerClick": 10,
101+
"offerId": "F1A2LqSYD3u"
102+
},
103+
{
104+
"offerClick": 15,
105+
"offerId": "F1MGDprRRJP"
106+
},
107+
{
108+
"offerClick": 7,
109+
"offerId": "F1MGDprnv7y"
110+
}
111+
]);
112+
113+
done();
114+
});
60115

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

0 commit comments

Comments
 (0)