|
@@ -122,8 +122,8 @@ var mapping = ` "mappings": {
|
|
}
|
|
}
|
|
}`
|
|
}`
|
|
|
|
|
|
-//createIndex 创建索引
|
|
|
|
-func createIndex(clients map[string]*elastic.Client, PreBiddingIndex string) error {
|
|
|
|
|
|
+//CreateIndex 创建索引
|
|
|
|
+func CreateIndex(clients map[string]*elastic.Client, PreBiddingIndex string) error {
|
|
//createJson := fmt.Sprintf(`{%s,%s}`, setting, mapping)
|
|
//createJson := fmt.Sprintf(`{%s,%s}`, setting, mapping)
|
|
|
|
|
|
for k, client := range clients {
|
|
for k, client := range clients {
|
|
@@ -302,6 +302,72 @@ func deleteIndex(clients map[string]*elastic.Client, index string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+//dealIndexByHour 处理预处理索引,根据小时;
|
|
|
|
+func dealIndexByHour() {
|
|
|
|
+ now := time.Now()
|
|
|
|
+ PreBiddingIndex := ""
|
|
|
|
+
|
|
|
|
+ var clients = make(map[string]*elastic.Client, 0)
|
|
|
|
+ for k, 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))
|
|
|
|
+ }
|
|
|
|
+ clients[k] = client
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ next := now.Add(time.Hour)
|
|
|
|
+ month := int(next.Month())
|
|
|
|
+ monthStr := strconv.Itoa(month)
|
|
|
|
+ year := next.Year()
|
|
|
|
+ yearStr := strconv.Itoa(year)
|
|
|
|
+ dayStr := strconv.Itoa(next.Day())
|
|
|
|
+ hour := next.Hour()
|
|
|
|
+ hourStr := strconv.Itoa(hour)
|
|
|
|
+ //下一天的索引名称
|
|
|
|
+ PreBiddingIndex = "bidding_" + yearStr + monthStr + dayStr + hourStr
|
|
|
|
+
|
|
|
|
+ err := CreateIndex(clients, PreBiddingIndex)
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Info("dealIndexByHour", zap.Error(err))
|
|
|
|
+ SendMail("预处理索引", "预处理索引创建失败,请检查")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ log.Info("dealIndexByHour", zap.String(PreBiddingIndex, "创建成功"))
|
|
|
|
+ //3. 删除昨天的索引
|
|
|
|
+ last := now.Add(-time.Hour)
|
|
|
|
+ month2 := int(last.Month())
|
|
|
|
+ monthStr2 := strconv.Itoa(month2)
|
|
|
|
+ year2 := last.Year()
|
|
|
|
+ yearStr2 := strconv.Itoa(year2)
|
|
|
|
+ dayStr2 := strconv.Itoa(last.Day())
|
|
|
|
+ hour2 := last.Hour()
|
|
|
|
+ hourStr2 := strconv.Itoa(hour2)
|
|
|
|
+ //索引名称
|
|
|
|
+ lastIndex := "bidding_" + yearStr2 + monthStr2 + dayStr2 + hourStr2
|
|
|
|
+ err = deleteIndex(clients, lastIndex)
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Info("dealIndexByHour", 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)
|
|
|
|
+}
|
|
|
|
+
|
|
//dealIndexByDay 处理预处理索引,根据天;
|
|
//dealIndexByDay 处理预处理索引,根据天;
|
|
func dealIndexByDay() {
|
|
func dealIndexByDay() {
|
|
now := time.Now()
|
|
now := time.Now()
|
|
@@ -336,7 +402,7 @@ func dealIndexByDay() {
|
|
//下一天的索引名称
|
|
//下一天的索引名称
|
|
PreBiddingIndex = "bidding_" + yearStr + monthStr + dayStr
|
|
PreBiddingIndex = "bidding_" + yearStr + monthStr + dayStr
|
|
|
|
|
|
- err := createIndex(clients, PreBiddingIndex)
|
|
|
|
|
|
+ err := CreateIndex(clients, PreBiddingIndex)
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Info("dealIndexByDay", zap.Error(err))
|
|
log.Info("dealIndexByDay", zap.Error(err))
|
|
SendMail("预处理索引", "预处理索引创建失败,请检查")
|
|
SendMail("预处理索引", "预处理索引创建失败,请检查")
|
|
@@ -403,7 +469,7 @@ func dealIndexByMonth() {
|
|
PreBiddingIndex = "bidding_" + yearStr + monthStr
|
|
PreBiddingIndex = "bidding_" + yearStr + monthStr
|
|
|
|
|
|
//2 创建下个月索引结构
|
|
//2 创建下个月索引结构
|
|
- err := createIndex(clients, PreBiddingIndex)
|
|
|
|
|
|
+ err := CreateIndex(clients, PreBiddingIndex)
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Info("dealIndexByMonth", zap.Error(err))
|
|
log.Info("dealIndexByMonth", zap.Error(err))
|
|
SendMail("预处理索引", "预处理索引创建失败,请检查")
|
|
SendMail("预处理索引", "预处理索引创建失败,请检查")
|