好吧,感谢@Leogiciel的 Max reduce 功能,我终于找到了解决方案。首先,视图定义保持不变。解决方案是使用Max reduce 函数的这个实现,最重要的是,使用查询参数进行分组和归约。
初始结果集,此处显示为原始 Json:
{"total_rows":9,"rows":[
{"id":"wound1Image1","key":"0a41d087-1a7f-4d9f-8df9-83d0deb2566c","value":1},
{"id":"wound2QualificationRev1","key":"4816f76e-33f9-456a-9e23-961799883994","value":1},
{"id":"wound2QualificationRev2","key":"4816f76e-33f9-456a-9e23-961799883994","value":2},
{"id":"wound2Image3","key":"65ff979a-e1e0-43d4-a24f-a3ee0cc8b67c","value":1},
{"id":"wound2Image1","key":"69f29cf8-3ee7-4681-937d-d465edc9bb16","value":1},
{"id":"wound1Image2","key":"76ab9a67-a17b-4fc6-a105-60b57e971d4f","value":1},
{"id":"wound1Synthesis","key":"bc1a7ec0-30d7-4493-8dd9-dcf6d0b48cc9","value":1},
{"id":"wound1Qualification","key":"cb375a5f-e07d-449a-ab13-60dba16a0323","value":1},
{"id":"wound2Image2","key":"dfb5e7eb-6192-46ba-84d2-0e5996536930","value":1}
]
}
使用以下查询参数:
?group=true&reduce=true
返回正确的结果集:
{"rows":[
{"key":"0a41d087-1a7f-4d9f-8df9-83d0deb2566c","value":1},
{"key":"4816f76e-33f9-456a-9e23-961799883994","value":2},
{"key":"65ff979a-e1e0-43d4-a24f-a3ee0cc8b67c","value":1},
{"key":"69f29cf8-3ee7-4681-937d-d465edc9bb16","value":1},
{"key":"76ab9a67-a17b-4fc6-a105-60b57e971d4f","value":1},
{"key":"bc1a7ec0-30d7-4493-8dd9-dcf6d0b48cc9","value":1},
{"key":"cb375a5f-e07d-449a-ab13-60dba16a0323","value":1}, {"key":"dfb5e7eb-6192-46ba-84d2-0e5996536930","value":1}
]
}