【发布时间】:2017-02-16 20:25:21
【问题描述】:
我正在尝试在自定义 reduce 函数(启用 rereduce)中聚合从我的地图发出的多个值,但我在结果中得到空值,除了我看到 0 的少数数据点。非常感谢任何帮助。谢谢
我发出的数据格式如下:
Key:"dateX" Values:"{'a':435, 'b':5645}"
Key:"dateX" Values:"{'a':8451, 'b':9245}"
Key:"dateX" Values:"{'a':352, 'b':450}"
Key:"dateY" Values:"{'a':5675, 'b':1245}"
Key:"dateY" Values:"{'a':4455, 'b':620}"
我想对 dateX 和 dateY 的 a & b 的值进行聚合/求和,我的 map-reduce 是:
"map": "function(doc){emit(doc.logDate, {'a': doc.a, 'b': doc.b} );}",
"reduce": "function(key, values, rereduce) {
var total = {tA:0, tB:0};
if(rereduce){
for(i=0; i<values.length; i++)
{
total.tA += values[i].a;
total.tB += values[i].b;
}
return total;
}
total.tA = sum(values.a);
total.tB = sum(values.b);
return total; }"
------------------------
Results:
dateX {tA: 0, tB: 0}
dateY {tA: null, tB: null}
dateZ {tA: null, tB: null}
.
.
.
【问题讨论】: