【发布时间】:2016-08-23 17:10:50
【问题描述】:
我是弹性搜索的新手。我想找到最近访问过的前 10 个唯一的 doc_id。
我已经对 doc_id 进行了第一次聚合,并添加了子聚合来对每个组进行排序并获得一个结果。现在我想对这个桶进行排序。 我无法根据 view_timestamp 对存储桶的结果进行排序。如何在第一次聚合期间添加订单?
我已经尝试过针对堆栈溢出给出的其他解决方案,但它对我不起作用。谁能帮我解决这个问题?
查询
{
"query": {
"constant_score": {
"filter": {
"term": { "username": "nil@gmail.com" }
}
}
},
"size":0,
"aggs":{
"title": {
"terms": {
"field": "doc_id",
"size":0
}
,
"aggs": {
"top": {
"top_hits": {
"sort": [
{
"viewed_timestamp": {
"order": "desc"
}
}
],
"size": 1
}
}
}
}
}
}
桶结果:
{
"aggregations": {
"title": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [{
"key": "b003",
"doc_count": 3,
"top_tag_hits": {
"hits": {
"total": 3,
"max_score": null,
"hits": [{
"_index": "visitedData",
"_type": "userdoc",
"_id": "AVak51Sp",
"_score": null,
"_source": {
"viewed_timestamp": "20160819T152359",
"content_type": "bp",
"title": "Data print",
"doc_id": "BP003"
},
"sort": [
1471620239000
]
}]
}
}
}, {
"key": "bp004",
"doc_count": 3,
"top_tag_hits": {
"hits": {
"total": 3,
"max_score": null,
"hits": [{
"_index": "visitedData",
"_type": "userdoc",
"_id": "AVak513Y8G",
"_score": null,
"_source": {
"viewed_timestamp": "20160819T152401",
"content_type": "bp",
"title": "Application Print",
"doc_id": "BP004"
},
"sort": [
1471620241000
]
}]
}
}
}]
}
}
}
【问题讨论】:
标签: elasticsearch