Hello,World

新手查询求助,思考了好久没用思路

Kibana | 作者 noob | 发布于2023年03月06日 | 阅读数:3122

软件版本:7.8
收集的登录日志,如何查询每个用户的最后登录时间?query语句应该咋写呀?尝试过聚合,但是聚合貌似只能导出登录过的用户。
GET aws-fortigate-*/_search
{
  "size": 10000, 
  "query": {
    "bool": {
      "must": [
        {
          "match_phrase": {
            "syslog.action": "tunnel-up"
          }
        },
        {
          "match_phrase": {
            "syslog.tunneltype": "ssl-tunnel"
          }
        }
      ]
    }
  },
  "_source": ["syslog.user","syslog.eventtime","@timestamp"]
}
这样是查询出所有的登录事件,还需要如何修改
已邀请:

FFFrp

赞同来自:

第一层terms agg user,第二层 max agg eventtime

caryliang - es使用工程师

赞同来自:

sort排序不行吗?

liujiacheng

赞同来自:

{
"size": 0,
"aggs": {
"user": {
"terms": {
"field": "name.keyword",
"size": 10
},
"aggs": {
"top": {
"top_hits": {
"size": 1,
"sort": [
{
"login_time": {
"order": "desc"
}
}
]
}
}
}
}
}
}

要回复问题请先登录注册