浏览代码

删除 bidding_extract 过期数据

wcc 1 年之前
父节点
当前提交
c4b2f26f7d
共有 1 个文件被更改,包括 17 次插入61 次删除
  1. 17 61
      pre_extract/es.go

+ 17 - 61
pre_extract/es.go

@@ -356,7 +356,15 @@ func dealIndexByDay() {
 	if err != nil {
 		log.Info("dealIndexByDay", zap.Error(err))
 	}
-	//}
+
+	//4. 删除bidding_extract  过期数据
+	where := map[string]interface{}{
+		"comeintime": map[string]interface{}{
+			"$lte": last.Unix(),
+		},
+		"is_pre": 1,
+	}
+	MgoB.Delete("bidding_extract", where)
 }
 
 //dealIndexByMonth 处理预处理索引,根据月份;提前一天创建好 下个月的索引
@@ -414,70 +422,18 @@ func dealIndexByMonth() {
 		if err != nil {
 			log.Info("dealIndexByMonth", zap.Error(err))
 		}
+		//4. 删除bidding_extract  过期数据
+		where := map[string]interface{}{
+			"comeintime": map[string]interface{}{
+				"$lte": last.Unix(),
+			},
+			"is_pre": 1,
+		}
+		MgoB.Delete("bidding_extract", where)
 	}
 
 }
 
-////SwitchAlias 切换别名
-//func SwitchAlias() {
-//	now := time.Now()
-//	// 判断当前时间是否为当前月份的最后一天
-//	//按日创建索引
-//	if GF.Env.SpecType == "day" {
-//		dealAlias()
-//	} else if GF.Env.SpecType == "month" {
-//		// 获取当前月份的最后一天
-//		lastDayOfMonth := time.Date(now.Year(), now.Month()+1, 0, 0, 0, 0, 0, time.UTC)
-//		//按月创建索引
-//		if now.Day() == lastDayOfMonth.Day() {
-//			dealAlias()
-//		}
-//	}
-//}
-//
-////dealAlias 处理 索引别名
-//func dealAlias() {
-//	now := time.Now()
-//
-//	for _, v := range GF.ES {
-//		url := v.URL
-//		username := v.Username
-//		password := v.Password
-//		// 创建 Elasticsearch 客户端
-//		client, err := elastic.NewClient(
-//			elastic.SetURL(url),
-//			elastic.SetBasicAuth(username, password),
-//			elastic.SetSniff(false),
-//		)
-//		if err != nil {
-//			log.Error("创建 Elasticsearch 客户端失败:", zap.Error(err))
-//		}
-//
-//		preBiddingIndex := "" //下一个索引名称
-//		next := now.AddDate(0, 0, 1)
-//		month := int(next.Month())
-//		monthStr := strconv.Itoa(month)
-//		year := next.Year()
-//		yearStr := strconv.Itoa(year)
-//		dayStr := strconv.Itoa(next.Day())
-//		if GF.Env.SpecType == "month" {
-//			//下一个月的索引名称
-//			preBiddingIndex = "bidding_" + yearStr + monthStr
-//		} else if GF.Env.SpecType == "day" {
-//			//下一天的索引名称
-//			preBiddingIndex = "bidding_" + yearStr + monthStr + dayStr
-//		}
-//
-//		for _, alias := range GF.Env.Alias {
-//			_, err = client.Alias().Add(preBiddingIndex, alias).Do(context.Background())
-//			if err != nil {
-//				log.Error("添加别名失败:", zap.Error(err))
-//			}
-//		}
-//		log.Info("dealAlias", zap.String(url, "索引别名处理完毕"))
-//	}
-//}
-
 //SendMail 发送邮件
 func SendMail(title, content string) {
 	url := fmt.Sprintf("%s?to=%s&title=%s&body=%s", GF.Email.Api, GF.Email.To, title, content)