{
"track_total_hits":true,
"query": {
"bool": {
"must": [
{
"term": {
"rtype.keyword": "010100"
}
},
{
"prefix": {
"incharge_wa_department.keyword": "34"
}
}
]
}
}
}
而要在文档数大于10000时获取实际的数量,需要加入参数:track_total_hits
track_total_hits=true表示显示实际的文档数,此时hits.total的会变成:
java代码
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(booleanQuery)
//排序
.withSort(SortBuilders.fieldSort(MessageAppAnalyze.CAPTURE_TIME).order(SortOrder.DESC))
//聚合
.addAggregation(fasAgg)
.withPageable(PageRequest.of(0, 10)).build();
// 搜索,获取结果
searchQuery.setTrackTotalHits(true);