Mapreduce 莫名其妙;“降幅过大”;错误

Mapreduce 莫名其妙;“降幅过大”;错误,mapreduce,couchbase,Mapreduce,Couchbase,我有一个文件桶,格式如下: { "a": 1, "b": 2, "c": 3, "d": 4, "e": 5 } 这是我的映射函数: function (doc, meta) { var summary = { b: doc.b, c: doc.c, history: [{ d: doc.d, e: doc.e }] }; emit(doc.a, summary); } function(key, val

我有一个文件桶,格式如下:

{
  "a": 1,
  "b": 2,
  "c": 3,
  "d": 4,
  "e": 5
}
这是我的映射函数:

function (doc, meta) {
  var summary = {
    b: doc.b,
    c: doc.c,
    history: [{
      d: doc.d,
      e: doc.e
    }]
  };
  emit(doc.a, summary);
}
function(key, values, rereduce) {
  for (i = 1; i < values.length; ++i)
    Array.prototype.push.apply(values[0].history, values[i].history);
  return values[0];
}
下面是我的reduce函数:

function (doc, meta) {
  var summary = {
    b: doc.b,
    c: doc.c,
    history: [{
      d: doc.d,
      e: doc.e
    }]
  };
  emit(doc.a, summary);
}
function(key, values, rereduce) {
  for (i = 1; i < values.length; ++i)
    Array.prototype.push.apply(values[0].history, values[i].history);
  return values[0];
}
这种组合会导致
减少过大的
错误。目前,我的数据集中最多有两个相同的键,因此我可以将reduce函数更改为:

function(key, values, rereduce) {
  if (values[1])
    Array.prototype.push.apply(values[0].history, values[1].history);
  return values[0];
}
function(key, values, rereduce) {
  if (rereduce) return "whatisgoingon";
  for (i = 1; i < values.length; ++i)
    Array.prototype.push.apply(values[0].history, values[i].history);
  return values[0];
}
保持其他一切不变,我会得到我想要的确切结果:

{  
   "key":1,
   "value":{  
      "b":2,
      "c":3,
      "history":[  
         {  
            "d":4,
            "e":5
         },
         {  
            "d":6,
            "e":7
         }
      ]
   }
}, many more like this
但是,我希望键的数量会随着时间的推移而增加,因此我需要能够循环使用

我还将reduce函数更改为只返回
值。length
以检查它是否返回了不合理的值,但我得到的结果不是
1
就是
2

发生了什么事

更新:

当我将reduce函数更改为:

function(key, values, rereduce) {
  if (values[1])
    Array.prototype.push.apply(values[0].history, values[1].history);
  return values[0];
}
function(key, values, rereduce) {
  if (rereduce) return "whatisgoingon";
  for (i = 1; i < values.length; ++i)
    Array.prototype.push.apply(values[0].history, values[i].history);
  return values[0];
}
函数(键、值、返回值){
如果(返回)返回“whatisgoingon”;
对于(i=1;i

我得到了我想要的结果,但是在视图结果中找不到
whatisingon
。我不想“放弃”rereduce逻辑,因为我将来可能会实际使用它,所以我需要了解问题的原因。

REREREDUCE是强制性的,您必须实现它。你读过了吗?我的reduce和rereduce案例使用相同的逻辑,因此严格来说,不必实现单独的rereduce流程。如前所述,通过使用静态数组索引示例,我得到了正确的结果,该示例没有返回流。