我在mongodb中有如下文档
{
"_id":"993208_1",
"clientId":"1",
"searchQueryAnalysisObj":[
{
"searchKeyword":"coat",
"searchKeywordScore":0.7,
"searchAnalysisModifiedDate": ISODate("2018-08-20T11:53:08.228Z")
},
{
"searchKeyword":"wire",
"searchKeywordScore":1.2,
"searchAnalysisModifiedDate":ISODate("2018-09-20T11:53:08.228Z")
}
],
"_class":"com.client.model.MainClickStreamData"
}
在searchQueryAnalysis对象中可以有多个对象,其中包含searchKeyword,searchKeywordScore和searchAnalysisModifiedDate。
我想基于searchKeywordScore春季查询的值对结果进行排序,以使searchKeywordScore在任何searchQueryAnalysis中具有最大值,我将首先获得该文档,就像我想获得前10条记录一样。
我正在尝试将其排序为
Query clientData = new Query(Criteria.where("clientId").is(clientId));
clientData.with(new Sort(new Order(Direction.DESC, "searchKeywordScore")));
List<ClickNavigationBrandData> allProcessedClicks = mongoOperation.find(clientData, ClickNavigationBrandData.class);
但是不能。
有人可以帮我吗?
谢谢
答案 0 :(得分:0)
我解决了这个问题-
> Query clientData = new Query(Criteria.where("clientId").is(clientId));
> clientData.with(new Sort(Direction.DESC,
> "searchQueryAnalysisObj.searchKeywordScore"));
> clientData.limit(10);