123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package main
- import (
- "fmt"
- "github.com/olivere/elastic/v7"
- "strconv"
- "testing"
- "time"
- )
- func TestMonth(T *testing.T) {
- // 创建2023年12月31日的时间对象
- date := time.Date(2023, time.August, 30, 0, 0, 0, 0, time.UTC)
- next := date.AddDate(0, -1, -1)
- month := int(next.Month())
- monthStr := strconv.Itoa(month)
- year := next.Year()
- yearStr := strconv.Itoa(year)
- //预处理索引名称
- PreBiddingIndex := "bidding_" + yearStr + monthStr
- fmt.Sprintf(PreBiddingIndex)
- }
- func TestDeleteIndex(t *testing.T) {
- data := map[string]string{
- "aa": "aaa",
- "bb": "bbb",
- "cc": "ccc",
- }
- for _, v := range data {
- if v == "aaa" {
- return
- }
- fmt.Println(v)
- }
- }
- //TestCreateIndex 创建索引
- func TestCreateIndex(t *testing.T) {
- 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 {
- fmt.Println("创建 Elasticsearch 客户端失败", err)
- }
- clients[k] = client
- }
- err := CreateIndex(clients, "bidding_2023112214")
- fmt.Println(err)
- }
|