查询需求:
# 根据describe下的ruleType 字段分组,查询各个ruleType对应的个数。
1.文档内容如下
{
"_id" : "593700197",
"_class" : "com.sefon.demo",
"describe" : [
{
"ruleType" : "FieldFormatVerify",
"ruleDetails" : "内容的格式或者长度不正确,正确格式为 c.. 8.0"
},
{
"ruleType" : "SFFieldDefect",
"ruleDetails" : "内容为空"
}
],
"findTime" : NumberLong(1550928738469)
},
{
"_id" : "593700198",
"_class" : "com.sefon.demo",
"describe" : [
{
"ruleType" : "FieldFormatVerify",
"ruleDetails" : "内容的格式或者长度不正确,正确格式为 c.. 8.0"
}
],
"findTime" : NumberLong(1550928738469)
}
2.本人使用的查询语句
Aggregation agg = newAggregation(
Aggregation.match(criteria),
Aggregation.unwind("describe"),
Aggregation.group("describe.ruleType").count().as("count")
);
List<DBObject> describeGroup = mongoOperations.aggregate(agg, ProblemInfo.class, DBObject.class).getMappedResults();
3.数据总量是200万,此聚合查询需要5秒左右,如何做能提升查询速度呢?
我已做如下索引创建,没有任何提升,求大神提供解决方案
db.problemInfo.ensureIndex({"ruleType":1});
db.problemInfo.ensureIndex({"describe":1});
db.problemInfo.ensureIndex({"describe.ruleType":1});