mapreduce查询返回部分原始数据

晓风_残月 发布于 2016/05/25 17:56
阅读 86
收藏 0
需求:需要返回每个分组固定数量的doc


实现:通过jar调用mapreduce方法,实现获取分组的部分数据。


环境:mongo-java-driver-3.2.jar mongodb-3.2
部分代码:
                String map="function (){emit(this.domain,{_id:this._id} )}";

String reduce="function(key,values){ var str;for(var doc in values){"
+ "              str=values[0];break;} return {\"docs\":str}; }";
MapReduceIterable<Document> mri=collect.mapReduce(map, reduce);
MongoCursor<Document> mc=mri.iterator();
int n=0;
while(mc.hasNext()){
n++;
Document doc=mc.next();
System.out.println(doc.toJson());
}


结果输出:
 { "_id" : "alfaporn.com", "value" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "_id" : "d113e8d2850f0944402f3129318a9043" } } } } } } } } } } } } } }
{ "_id" : "all-femdom-movies.com", "value" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "_id" : "3238cd2caf98bf7961089e36ca33a67b" } } } } } } } } } } } } } } } } } } } }
{ "_id" : "allasiangals.com", "value" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "_id" : "ad8200df9d862631a8e3420c3185e210" } } } } } } }
{ "_id" : "allcartoonshere.com", "value" : { "docs" : { "docs" : { "docs" : { "docs" : { "_id" : "120eb8ade2d0665feb599748c3bd3c1d" } } } } } }
{ "_id" : "allcfnmporn.com", "value" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "_id" : "74d321593f289d25400ddfc712ddfa4b" } } } } } } } } } } } } }
{ "_id" : "allfreehardcore.com", "value" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "_id" : "c25bfbc7ea131affd9458680a40f7e18" } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } }
{ "_id" : "allgaydreams.com", "value" : { "docs" : { "docs" : { "_id" : "9343cff09d737eee511663898cd794cc" } } } }
{ "_id" : "allmaturegals.com", "value" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "_id" : "ef1be6af33be28752a3998bc24d515fe" } } } } } } } } } } } } } } } } } } } } } } } } } } } }
{ "_id" : "allrusporno.com", "value" : { "docs" : { "_id" : "1f540dd64fd45200e5ed0d51a0551546" } } }
{ "_id" : "allsweetcartoons.com", "value" : { "docs" : { "docs" : { "docs" : { "_id" : "5cc7831ac9b088987f5eb48e78ff0c46" } } } } }
{ "_id" : "alvahardcore.com", "value" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "docs" : { "_id" : "e47a5c01101395d25ff36c2be3d7af1d" } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } }




输出结果出现大量重叠的docs,求大神指点
加载中
返回顶部
顶部