沙师弟,师父的充电器掉了

求教 这个 DSL该怎么写?

Elasticsearch | 作者 you_know | 发布于2019年12月13日 | 阅读数:648

现在有两个字段 userId 和 time
同一个userId下可能有很多个time值
现在想在一次查询中查到多个userId 下最大的time值
(一个userid term + sort 很容易实现 多个userId 该怎么写)
已邀请:

core_wzw - 某AILab搜索技术负责人

赞同来自:

是很容易写,别做伸手党了,自己写写吧。

you_know - 98

赞同来自:

{  
    "size":0,
    "aggs": {
        "top": {
            "terms": {
                "field": "userid"
            },
            "aggs": {
                "top_time_hits": {
                    "top_hits": {
                        "sort": [
                            {
                                "time": {
                                    "order": "desc"
                                }
                            }
                        ], 
                        "size" : 1
                    }
                }
            }
        }
    }
}'

要回复问题请先登录注册