一、查询结果按某个字段进行排序
{
"size" : 5,
"query" : {
"bool" : {
"filter" : [
{
"range" : {
"startTime" : {
"from" : 1517046960000,
"to" : 1517048760000
}
}
}
]
}
},
"sort" : [{ "startTime" : { "order" : "desc"}}
]
}
//javaApi设置查询数量size和对orderstr进行正序
SearchRequestBuilder srb = this.createSearchRequestBuilder(new Date(begin), new Date(end));
srb.setQuery(queryBuilder).setSize(queryParam.getPageIndex() * queryParam.getPageSize())
.addSort(orderStr, SortOrder.ASC);
二、聚合结果进行排序
1、根据查询到文档数量
聚合结果为查询到文档的数量倒序:"order" : { "_count" : "desc" }
{"size":