本文介绍了排序elasticsearch热门结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Elasticsearch中执行查询,以从特定日期范围重新使用特定用户.结果应按userId分组并在trackTime字段上排序,我能够通过使用聚合来使用组,但是我无法在tracktime上对聚合存储桶进行排序,因此我写下了以下查询
I am trying to execute a query in elasticsearch to get reuslt of specific users from certain date range. the results should be grouped by userId and sorted on trackTime field, I am able to use group by using aggregation but i am not able to sort aggregation buckets on tracktime, i write down the following query
GET _search
{
"size": 0,
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"range": {
"trackTime": {
"from": "2016-02-08T05:51:02.000Z"
}
}
}
]
}
},
"filter": {
"terms": {
"userId": [
9,
10,
3
]
}
}
}
},
"aggs": {
"by_district": {
"terms": {
"field": "userId"
},
"aggs": {
"tops": {
"top_hits": {
"size": 2
}
}
}
}
}
}
我还应该使用什么来对热门结果进行排序?预先感谢...
what more should i have to use to sort the top hits result? Thanks in advance...
推荐答案
您可以像使用 sort
一样.
"aggs": {
"by_district": {
"terms": {
"field": "userId"
},
"aggs": {
"tops": {
"top_hits": {
"sort": [
{
"fieldName": {
"order": "desc"
}
}
],
"size": 2
}
}
}
}
}
希望有帮助
这篇关于排序elasticsearch热门结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!