获取时间窗口的楼层

最好的方法是使用分区


根据文档:


GET /_search

{

   "size": 0,

   "aggs": {

      "expired_sessions": {

         "terms": {

            "field": "account_id",

            "include": {

               "partition": 1,

               "num_partitions": 25

            },

            "size": 20,

            "order": {

               "last_access": "asc"

            }

         },

         "aggs": {

            "last_access": {

               "max": {

                  "field": "access_date"

               }

            }

         }

      }

   }

}

https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-terms-aggregation.html#_filtering_values_with_partitions


蝴蝶不菲
浏览 69回答 1
1回答

交互式爱情

如果你想向下舍入时间,请使用time.Truncate:t := time.Now()fmt.Println(t.Truncate(5*time.Second))将此应用到您的需求:// returns in UTC timezone - regardless of input timezonefunc getWindow(t time.Time, windowLength time.Duration, step int64) time.Time {    return t.UTC().Truncate(windowLength).Add(        time.Duration(step) * windowLength,    )}// time.Now() may be in any timezone - but UTC will be returned (see above)func GetWindow(windowLength time.Duration, step int64) time.Time {    return getWindow(time.Now(), windowLength, step)}具有替代时区等的演示:https ://play.golang.org/p/gqsT4LvWdDi添加到您的测试代码:https://play.golang.org/p/UDPlsR6IGPw
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python