亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

獲取時間窗口的樓層

獲取時間窗口的樓層

蝴蝶不菲 2023-08-08 16:46:24
最好的方法是使用分區根據文檔: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
查看完整描述

1 回答

?
交互式愛情

TA貢獻1712條經驗 獲得超3個贊

如果你想向下舍入時間,請使用time.Truncate:

t := time.Now()

fmt.Println(t.Truncate(5*time.Second))

將此應用到您的需求:


// returns in UTC timezone - regardless of input timezone

func 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


查看完整回答
反對 回復 2023-08-08
  • 1 回答
  • 0 關注
  • 114 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號