欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ES 时间范围内过滤

程序员文章站 2024-02-08 18:01:40
...
GET /apps_zego_logs-2018.09.25/_search
{
   "size": 1,
   "query": {
     "bool": {
       "must": [
         {"range": {
           "@timestamp": {
             "gte": "now-1h",
             "lte": "now",
             "format": "yyyy-MM-dd-HH",
             "time_zone":"+08:00"
           }
         }
         }
       ]
     }
   },
  "aggs": {
    "diff_user": {
      "cardinality" : {
        "field": "userid.keyword"
      }
    },
    "over_time" : {
      "date_histogram" : {
        "field" : "@timestamp",
        "interval" : "minute",
        "format": "yyyy-MM-dd-HH-mm",
        "time_zone":"+08:00",
        "min_doc_count" : 0
      },
      "aggs": {
        "diff_user": {
          "cardinality" : {
            "field": "userid.keyword"
          }
        }
      }
    }
  },
  "collapse": {
    "field": "userid.keyword"
  }
}