[备忘]es查询之按天聚合

需求:渠道每日活跃统计(定时任务每日凌晨执行一次)

{
    "query": {
        "bool": {
            "must": [
                {
                    "range": {
                        "unixtime": {
                            "gt": "$start_time",
                            "lt": "$end_time"
                        }
                    }
                },
                {
                    "term": {
                        "statFunc":"login"
                    }
                },
                {
                    "term": {
                        "num":1
                    }
                }
            ],
            "must_not": [],
            "should": []
        }
    },
    "from": 0,
    "size": 0,
     "sort": [
    {
      "unixtime": {
        "order": "desc"
      }
    }
  ],
    "aggs": {
        "total": {
            //将aggs上面查询语句查询的结果进行选定
            "terms": {
                "field": "channelTag",//对字段名为channelTag的数据进行选定
                "size": 1000000
            },
            //对选定后的数据进行按日(date_histogram)分组
            "aggs": {
                "record": {
                    //date_histogram分组标识
                    "date_histogram": {
                        "field": "@timestamp",
                        "interval": "1d",//按日分组
                        "time_zone": "Asia/Shanghai",
                        "min_doc_count": 0
                    }
                }
            }
        }
    }
}

END

猜你喜欢

转载自blog.csdn.net/qq_15941409/article/details/120723472
今日推荐