Jelajahi Sumber

Merge branch 'v1'

* v1:
  md
  no message
  删除 es7 版本中type 字段
  no message
  no message
  添加用户密码
  no message
  no message
  no message
  no message
  no message
  no message
  es批量保存
  id
  no message
  id
  no message
  no message
  no message
Jianghan 2 tahun lalu
induk
melakukan
e053eac2b2
6 mengubah file dengan 466 tambahan dan 284 penghapusan
  1. 138 133
      elastic/elasticSim.go
  2. 72 0
      elastic/elastic_test.go
  3. 162 143
      elastic/elasticutil.go
  4. 1 2
      go.mod
  5. 93 4
      go.sum
  6. 0 2
      mysqldb/mysql.go

+ 138 - 133
elastic/elasticSim.go

@@ -1,11 +1,12 @@
 package elastic
 
 import (
+	util "app.yhyue.com/data_processing/common_utils"
 	"context"
 	"encoding/json"
 	"errors"
 	"fmt"
-	es "gopkg.in/olivere/elastic.v2"
+	es "github.com/olivere/elastic/v7"
 	"log"
 	"runtime"
 	"strings"
@@ -21,6 +22,8 @@ type Elastic struct {
 	lastTime     int64
 	lastTimeLock sync.Mutex
 	ntimeout     int
+	Username     string
+	Password     string
 }
 
 func (e *Elastic) InitElasticSize() {
@@ -29,7 +32,7 @@ func (e *Elastic) InitElasticSize() {
 		e.Addrs = append(e.Addrs, s)
 	}
 	for i := 0; i < e.I_size; i++ {
-		client, _ := es.NewClient(es.SetURL(e.Addrs...), es.SetMaxRetries(2), es.SetSniff(false))
+		client, _ := es.NewClient(es.SetURL(e.Addrs...), es.SetBasicAuth(e.Username, e.Password), es.SetMaxRetries(2), es.SetSniff(false))
 		e.Pool <- client
 	}
 }
@@ -52,7 +55,7 @@ func (e *Elastic) GetEsConn() *es.Client {
 	case c := <-e.Pool:
 		if c == nil || !c.IsRunning() {
 			log.Println("new esclient.", len(e.Pool))
-			client, err := es.NewClient(es.SetURL(e.Addrs...),
+			client, err := es.NewClient(es.SetURL(e.Addrs...), es.SetBasicAuth(e.Username, e.Password),
 				es.SetMaxRetries(2), es.SetSniff(false))
 			if err == nil && client.IsRunning() {
 				return client
@@ -69,10 +72,10 @@ func (e *Elastic) GetEsConn() *es.Client {
 		if c > 12 {
 			e.lastTime = time.Now().Unix()
 			log.Println("add client..", len(e.Pool))
-			c, _ := es.NewClient(es.SetURL(e.Addrs...), es.SetMaxRetries(2), es.SetSniff(false))
+			c, _ := es.NewClient(es.SetURL(e.Addrs...), es.SetBasicAuth(e.Username, e.Password), es.SetMaxRetries(2), es.SetSniff(false))
 			go func() {
 				for i := 0; i < 2; i++ {
-					client, _ := es.NewClient(es.SetURL(e.Addrs...), es.SetMaxRetries(2), es.SetSniff(false))
+					client, _ := es.NewClient(es.SetURL(e.Addrs...), es.SetBasicAuth(e.Username, e.Password), es.SetMaxRetries(2), es.SetSniff(false))
 					e.Pool <- client
 				}
 			}()
@@ -82,7 +85,7 @@ func (e *Elastic) GetEsConn() *es.Client {
 	}
 }
 
-func (e *Elastic) Get(index, itype, query string) *[]map[string]interface{} {
+func (e *Elastic) Get(index, query string) *[]map[string]interface{} {
 	client := e.GetEsConn()
 	defer func() {
 		go e.DestoryEsConn(client)
@@ -101,7 +104,7 @@ func (e *Elastic) Get(index, itype, query string) *[]map[string]interface{} {
 				}
 			}
 		}()
-		searchResult, err := client.Search().Index(index).Type(itype).Source(query).Do()
+		searchResult, err := client.Search().Index(index).Source(query).Do(context.Background())
 		if err != nil {
 			log.Println("从ES查询出错", err.Error())
 			return nil
@@ -111,7 +114,7 @@ func (e *Elastic) Get(index, itype, query string) *[]map[string]interface{} {
 			if resNum < 5000 {
 				res = make([]map[string]interface{}, resNum)
 				for i, hit := range searchResult.Hits.Hits {
-					parseErr := json.Unmarshal(*hit.Source, &res[i])
+					parseErr := json.Unmarshal(hit.Source, &res[i])
 					if parseErr == nil && hit.Highlight != nil && res[i] != nil {
 						res[i]["highlight"] = map[string][]string(hit.Highlight)
 					}
@@ -157,18 +160,20 @@ func (e *Elastic) Close() {
 //	}
 //}
 
-func (e *Elastic) BulkSave(index, itype string, obj *[]map[string]interface{}, isDelBefore bool) {
+func (e *Elastic) BulkSave(index string, obj []map[string]interface{}) {
 	client := e.GetEsConn()
 	defer e.DestoryEsConn(client)
 	if client != nil {
 		req := client.Bulk()
-		for _, v := range *obj {
-			if isDelBefore {
-				req = req.Add(es.NewBulkDeleteRequest().Index(index).Type(itype).Id(fmt.Sprintf("%v", v["_id"])))
-			}
-			req = req.Add(es.NewBulkIndexRequest().Index(index).Type(itype).Doc(v))
+		for _, v := range obj {
+			//if isDelBefore {
+			//	req = req.Add(es.NewBulkDeleteRequest().Index(index).Id(fmt.Sprintf("%v", v["_id"])))
+			//}
+			id := util.ObjToString(v["_id"])
+			delete(v, "_id")
+			req = req.Add(es.NewBulkIndexRequest().Index(index).Id(id).Doc(v))
 		}
-		_, err := req.Do()
+		_, err := req.Do(context.Background())
 		if err != nil {
 			log.Println("批量保存到ES出错", err.Error())
 		}
@@ -176,13 +181,13 @@ func (e *Elastic) BulkSave(index, itype string, obj *[]map[string]interface{}, i
 }
 
 //根据id删除索引对象
-func (e *Elastic) DelById(index, itype, id string) bool {
+func (e *Elastic) DelById(index, id string) bool {
 	client := e.GetEsConn()
 	defer e.DestoryEsConn(client)
 	b := false
 	if client != nil {
 		var err error
-		_, err = client.Delete().Index(index).Type(itype).Id(id).Do()
+		_, err = client.Delete().Index(index).Id(id).Do(context.Background())
 		if err != nil {
 			log.Println("更新检索出错:", err.Error())
 		} else {
@@ -191,8 +196,8 @@ func (e *Elastic) DelById(index, itype, id string) bool {
 	}
 	return b
 }
-func (e *Elastic) GetNoLimit(index, itype, query string) *[]map[string]interface{} {
-	//log.Println("query  -- ", query)
+
+func (e *Elastic) GetNoLimit(index, query string) *[]map[string]interface{} {
 	client := e.GetEsConn()
 	defer e.DestoryEsConn(client)
 	var res []map[string]interface{}
@@ -209,7 +214,7 @@ func (e *Elastic) GetNoLimit(index, itype, query string) *[]map[string]interface
 				}
 			}
 		}()
-		searchResult, err := client.Search().Index(index).Type(itype).Source(query).Do()
+		searchResult, err := client.Search().Index(index).Source(query).Do(context.Background())
 		if err != nil {
 			log.Println("从ES查询出错", err.Error())
 			return nil
@@ -219,54 +224,55 @@ func (e *Elastic) GetNoLimit(index, itype, query string) *[]map[string]interface
 			resNum := len(searchResult.Hits.Hits)
 			res = make([]map[string]interface{}, resNum)
 			for i, hit := range searchResult.Hits.Hits {
-				json.Unmarshal(*hit.Source, &res[i])
+				json.Unmarshal(hit.Source, &res[i])
 			}
 		}
 	}
 	return &res
 }
-func (e *Elastic) GetByIdField(index, itype, id, fields string) *map[string]interface{} {
-	client := e.GetEsConn()
-	defer e.DestoryEsConn(client)
-	if client != nil {
-		defer func() {
-			if r := recover(); r != nil {
-				log.Println("[E]", r)
-				for skip := 1; ; skip++ {
-					_, file, line, ok := runtime.Caller(skip)
-					if !ok {
-						break
-					}
-					go log.Printf("%v,%v\n", file, line)
-				}
-			}
-		}()
-		query := `{"query":{"term":{"_id":"` + id + `"}}`
-		if len(fields) > 0 {
-			query = query + `,"_source":[` + fields + `]`
-		}
-		query = query + "}"
-		searchResult, err := client.Search().Index(index).Type(itype).Source(query).Do()
-		if err != nil {
-			log.Println("从ES查询出错", err.Error())
-			return nil
-		}
-		var res map[string]interface{}
-		if searchResult.Hits != nil {
-			resNum := len(searchResult.Hits.Hits)
-			if resNum == 1 {
-				res = make(map[string]interface{})
-				for _, hit := range searchResult.Hits.Hits {
-					json.Unmarshal(*hit.Source, &res)
-				}
-				return &res
-			}
-		}
-	}
-	return nil
-}
 
-func (e *Elastic) Count(index, itype string, query interface{}) int64 {
+//func (e *Elastic) GetByIdField(index, itype, id, fields string) *map[string]interface{} {
+//	client := e.GetEsConn()
+//	defer e.DestoryEsConn(client)
+//	if client != nil {
+//		defer func() {
+//			if r := recover(); r != nil {
+//				log.Println("[E]", r)
+//				for skip := 1; ; skip++ {
+//					_, file, line, ok := runtime.Caller(skip)
+//					if !ok {
+//						break
+//					}
+//					go log.Printf("%v,%v\n", file, line)
+//				}
+//			}
+//		}()
+//		query := `{"query":{"term":{"_id":"` + id + `"}}`
+//		if len(fields) > 0 {
+//			query = query + `,"_source":[` + fields + `]`
+//		}
+//		query = query + "}"
+//		searchResult, err := client.Search().Index(index).Type(itype).Source(query).Do()
+//		if err != nil {
+//			log.Println("从ES查询出错", err.Error())
+//			return nil
+//		}
+//		var res map[string]interface{}
+//		if searchResult.Hits != nil {
+//			resNum := len(searchResult.Hits.Hits)
+//			if resNum == 1 {
+//				res = make(map[string]interface{})
+//				for _, hit := range searchResult.Hits.Hits {
+//					json.Unmarshal(*hit.Source., &res)
+//				}
+//				return &res
+//			}
+//		}
+//	}
+//	return nil
+//}
+
+func (e *Elastic) Count(index string, query interface{}) int64 {
 	client := e.GetEsConn()
 	defer e.DestoryEsConn(client)
 	if client != nil {
@@ -286,7 +292,7 @@ func (e *Elastic) Count(index, itype string, query interface{}) int64 {
 		if qi, ok2 := query.(es.Query); ok2 {
 			qq = qi
 		}
-		n, err := client.Count(index).Type(itype).Query(qq).Do()
+		n, err := client.Count(index).Query(qq).Do(context.Background())
 		if err != nil {
 			log.Println("统计出错", err.Error())
 		}
@@ -297,80 +303,79 @@ func (e *Elastic) Count(index, itype string, query interface{}) int64 {
 }
 
 //更新一个字段
-func (e *Elastic) BulkUpdateArr(index, itype string, update []map[string]string) {
-	client := e.GetEsConn()
-	defer e.DestoryEsConn(client)
-	if client != nil {
-		defer func() {
-			if r := recover(); r != nil {
-				log.Println("[E]", r)
-				for skip := 1; ; skip++ {
-					_, file, line, ok := runtime.Caller(skip)
-					if !ok {
-						break
-					}
-					go log.Printf("%v,%v\n", file, line)
-				}
-			}
-		}()
-		for _, data := range update {
-			id := data["id"]
-			updateStr := data["updateStr"]
-			if id != "" && updateStr != "" {
-				_, err := client.Update().Index(index).Type(itype).Id(id).Script(updateStr).ScriptLang("groovy").Do()
-				if err != nil {
-					log.Println("更新检索出错:", err.Error())
-				}
-			} else {
-				log.Println("数据错误")
-			}
-		}
-	}
-}
+//func (e *Elastic) BulkUpdateArr(index, itype string, update []map[string]string) {
+//	client := e.GetEsConn()
+//	defer e.DestoryEsConn(client)
+//	if client != nil {
+//		defer func() {
+//			if r := recover(); r != nil {
+//				log.Println("[E]", r)
+//				for skip := 1; ; skip++ {
+//					_, file, line, ok := runtime.Caller(skip)
+//					if !ok {
+//						break
+//					}
+//					go log.Printf("%v,%v\n", file, line)
+//				}
+//			}
+//		}()
+//		for _, data := range update {
+//			id := data["id"]
+//			updateStr := data["updateStr"]
+//			if id != "" && updateStr != "" {
+//				_, err := client.Update().Index(index).Type(itype).Id(id).Script(updateStr).ScriptLang("groovy").Do()
+//				if err != nil {
+//					log.Println("更新检索出错:", err.Error())
+//				}
+//			} else {
+//				log.Println("数据错误")
+//			}
+//		}
+//	}
+//}
 
 //更新多个字段
-func (e *Elastic) BulkUpdateMultipleFields(index, itype string, arrs [][]map[string]interface{}) {
-	client := e.GetEsConn()
-	defer e.DestoryEsConn(client)
-	if client != nil {
-		defer func() {
-			if r := recover(); r != nil {
-				log.Println("[E]", r)
-				for skip := 1; ; skip++ {
-					_, file, line, ok := runtime.Caller(skip)
-					if !ok {
-						break
-					}
-					go log.Printf("%v,%v\n", file, line)
-				}
-			}
-		}()
-		for _, arr := range arrs {
-			id := arr[0]["id"].(string)
-			update := arr[1]["update"].([]string)
-			for _, str := range update {
-				_, err := client.Update().Index(index).Type(itype).Id(id).Script(str).ScriptLang("groovy").Do()
-				if err != nil {
-					log.Println("更新检索出错:", err.Error())
-				}
-			}
-		}
-	}
-}
+//func (e *Elastic) BulkUpdateMultipleFields(index, itype string, arrs [][]map[string]interface{}) {
+//	client := e.GetEsConn()
+//	defer e.DestoryEsConn(client)
+//	if client != nil {
+//		defer func() {
+//			if r := recover(); r != nil {
+//				log.Println("[E]", r)
+//				for skip := 1; ; skip++ {
+//					_, file, line, ok := runtime.Caller(skip)
+//					if !ok {
+//						break
+//					}
+//					go log.Printf("%v,%v\n", file, line)
+//				}
+//			}
+//		}()
+//		for _, arr := range arrs {
+//			id := arr[0]["id"].(string)
+//			update := arr[1]["update"].([]string)
+//			for _, str := range update {
+//				_, err := client.Update().Index(index).Type(itype).Id(id).Script(str).ScriptLang("groovy").Do()
+//				if err != nil {
+//					log.Println("更新检索出错:", err.Error())
+//				}
+//			}
+//		}
+//	}
+//}
 
 // UpdateBulk 批量修改文档
-func (e *Elastic) UpdateBulk(index, itype string, docs ...[]map[string]interface{}) {
+func (e *Elastic) UpdateBulk(index string, docs ...[]map[string]interface{}) {
 	client := e.GetEsConn()
 	defer e.DestoryEsConn(client)
-	//bulkService := client.Bulk().Index(index).Refresh("true")
-	bulkService := client.Bulk().Index(index).Refresh(true)
-	bulkService.Type(itype)
+	bulkService := client.Bulk().Index(index).Refresh("true")
+	//bulkService.Type(itype)
 	for _, d := range docs {
 		id := d[0]["_id"].(string)
 		doc := es.NewBulkUpdateRequest().Id(id).Doc(d[1])
 		bulkService.Add(doc)
 	}
-	_, err := bulkService.Do()
+	_, err := bulkService.Do(context.Background())
 	if err != nil {
 		fmt.Printf("UpdateBulk all success err is %v\n", err)
 	}
@@ -383,18 +388,18 @@ func (e *Elastic) UpdateBulk(index, itype string, docs ...[]map[string]interface
 func (e *Elastic) UpsertBulk(ctx context.Context, index string, ids []string, docs []interface{}) error {
 	client := e.GetEsConn()
 	defer e.DestoryEsConn(client)
-	bulkService := client.Bulk().Index(index).Refresh(true)
-	bulkService.Type("bidding")
+	bulkService := client.Bulk().Index(index).Refresh("true")
+	//bulkService.Type("bidding")
 	for i := range ids {
 		doc := es.NewBulkUpdateRequest().Id(ids[i]).Doc(docs[i]).Upsert(docs[i])
 		bulkService.Add(doc)
 	}
-	res, err := bulkService.Do()
+	res, err := bulkService.Do(context.Background())
 	if err != nil {
 		return err
 	}
 	if len(res.Failed()) > 0 {
-		return errors.New(res.Failed()[0].Error)
+		return errors.New(res.Failed()[0].Error.Reason)
 	}
 	return nil
 }
@@ -403,13 +408,13 @@ func (e *Elastic) UpsertBulk(ctx context.Context, index string, ids []string, do
 func (e *Elastic) DeleteBulk(index string, ids []string) {
 	client := e.GetEsConn()
 	defer e.DestoryEsConn(client)
-	bulkService := client.Bulk().Index(index).Refresh(true)
-	bulkService.Type("bidding")
+	bulkService := client.Bulk().Index(index).Refresh("true")
+	//bulkService.Type("bidding")
 	for i := range ids {
 		req := es.NewBulkDeleteRequest().Id(ids[i])
 		bulkService.Add(req)
 	}
-	res, err := bulkService.Do()
+	res, err := bulkService.Do(context.Background())
 	if err != nil {
 		fmt.Printf("DeleteBulk success is %v\n", len(res.Succeeded()))
 	}

+ 72 - 0
elastic/elastic_test.go

@@ -0,0 +1,72 @@
+package elastic
+
+import (
+	"encoding/json"
+	"fmt"
+	es "github.com/olivere/elastic/v7"
+	"testing"
+)
+
+var esClinet Elastic
+
+//func init() {
+//	esClinet = Elastic{
+//		S_esurl:  "127.0.0.1:19805",
+//		I_size:   2,
+//		Username: "es_all",
+//		Password: "TopJkO2E_d1x",
+//	}
+//	fmt.Println(esClinet)
+//
+//	esClinet.InitElasticSize()
+//
+//}
+func TestCount(t *testing.T) {
+	esClinet = Elastic{
+		S_esurl:  "http://127.0.0.1:19805",
+		I_size:   2,
+		Username: "es_all",
+		Password: "TopJkO2E_d1x",
+	}
+	esClinet.InitElasticSize()
+
+	rangeQuery := es.NewRangeQuery("id").Gte("6463a8800000000000000000").Lt("6464fa000000000000000000")
+	termsQuery := es.NewTermsQuery("site", "元博网(采购与招标网)", "中国招标与采购网")
+	boolQuery := es.NewBoolQuery().Must(rangeQuery, termsQuery)
+
+	bytes, err := json.Marshal(boolQuery)
+	if err != nil {
+		fmt.Println("err", err.Error())
+	}
+
+	fmt.Println("qqq", string(bytes))
+	count1 := esClinet.Count("bidding", "", boolQuery)
+	fmt.Println(count1)
+}
+
+func TestBulkSave(t *testing.T) {
+	esClinet = Elastic{
+		S_esurl:  "http://127.0.0.1:19805",
+		I_size:   2,
+		Username: "es_all",
+		Password: "TopJkO2E_d1x",
+	}
+	esClinet.InitElasticSize()
+
+	id := "6398a381063a7b816e072adf"
+	esUpdate := map[string]interface{}{
+		"area":     "新疆",
+		"city":     "伊犁哈萨克自治州",
+		"district": "奎屯市",
+	}
+
+	updateEs := []map[string]interface{}{
+		{"_id": id},
+		esUpdate,
+	}
+
+	arru := make([][]map[string]interface{}, 0)
+	arru = append(arru, updateEs)
+	esClinet.UpdateBulk("bidding", arru...)
+	fmt.Println(arru)
+}

+ 162 - 143
elastic/elasticutil.go

@@ -1,9 +1,11 @@
 package elastic
 
 import (
+	"bytes"
+	"context"
 	"encoding/json"
 	"fmt"
-	es "gopkg.in/olivere/elastic.v2"
+	es "github.com/olivere/elastic/v7"
 	"log"
 	"net/url"
 	"reflect"
@@ -151,7 +153,7 @@ func Get(index, itype, query string) *[]map[string]interface{} {
 				}
 			}
 		}()
-		searchResult, err := client.Search().Index(index).Type(itype).Source(query).Do()
+		searchResult, err := client.Search().Index(index).Source(query).Do(context.Background())
 		if err != nil {
 			log.Println("从ES查询出错", err.Error())
 			return nil
@@ -162,10 +164,11 @@ func Get(index, itype, query string) *[]map[string]interface{} {
 			if resNum < 5000 {
 				res = make([]map[string]interface{}, resNum)
 				for i, hit := range searchResult.Hits.Hits {
-					//d := json.NewDecoder(bytes.NewBuffer(*hit.Source))
-					//d.UseNumber()
-					//d.Decode(&res[i])
-					parseErr := json.Unmarshal(*hit.Source, &res[i])
+					b, _ := hit.Source.MarshalJSON()
+					d := json.NewDecoder(bytes.NewBuffer(b))
+					d.UseNumber()
+					parseErr := d.Decode(&res[i])
+					//parseErr := json.Unmarshal(*hit.Source, &res[i])
 					if parseErr == nil && hit.Highlight != nil && res[i] != nil {
 						res[i]["highlight"] = map[string][]string(hit.Highlight)
 					}
@@ -199,7 +202,7 @@ func GetOA(index, itype, query string) (*[]map[string]interface{}, int) {
 				}
 			}
 		}()
-		searchResult, err := client.Search().Index(index).Type(itype).Source(query).Do()
+		searchResult, err := client.Search().Index(index).Source(query).Do(context.Background())
 		if err != nil {
 			log.Println("从ES查询出错", err.Error())
 			return nil, 0
@@ -210,10 +213,11 @@ func GetOA(index, itype, query string) (*[]map[string]interface{}, int) {
 			if resNum < 5000 {
 				res = make([]map[string]interface{}, resNum)
 				for i, hit := range searchResult.Hits.Hits {
-					//d := json.NewDecoder(bytes.NewBuffer(*hit.Source))
-					//d.UseNumber()
-					//d.Decode(&res[i])
-					parseErr := json.Unmarshal(*hit.Source, &res[i])
+					b, _ := hit.Source.MarshalJSON()
+					d := json.NewDecoder(bytes.NewBuffer(b))
+					d.UseNumber()
+					parseErr := d.Decode(&res[i])
+					//parseErr := json.Unmarshal(*hit.Source, &res[i])
 					if parseErr == nil && hit.Highlight != nil && res[i] != nil {
 						res[i]["highlight"] = map[string][]string(hit.Highlight)
 					}
@@ -245,7 +249,7 @@ func GetNoLimit(index, itype, query string) *[]map[string]interface{} {
 				}
 			}
 		}()
-		searchResult, err := client.Search().Index(index).Type(itype).Source(query).Do()
+		searchResult, err := client.Search().Index(index).Source(query).Do(context.Background())
 		if err != nil {
 			log.Println("从ES查询出错", err.Error())
 			return nil
@@ -255,7 +259,10 @@ func GetNoLimit(index, itype, query string) *[]map[string]interface{} {
 			resNum := len(searchResult.Hits.Hits)
 			res = make([]map[string]interface{}, resNum)
 			for i, hit := range searchResult.Hits.Hits {
-				json.Unmarshal(*hit.Source, &res[i])
+				b, _ := hit.Source.MarshalJSON()
+				d := json.NewDecoder(bytes.NewBuffer(b))
+				d.Decode(&res[i])
+				//json.Unmarshal(*hit.Source, &res[i])
 			}
 		}
 	}
@@ -401,7 +408,7 @@ func GetByIdField(index, itype, id, fields string) *map[string]interface{} {
 			query = query + `,"_source":[` + fields + `]`
 		}
 		query = query + "}"
-		searchResult, err := client.Search().Index(index).Type(itype).Source(query).Do()
+		searchResult, err := client.Search().Index(index).Source(query).Do(context.Background())
 		if err != nil {
 			log.Println("从ES查询出错", err.Error())
 			return nil
@@ -412,7 +419,11 @@ func GetByIdField(index, itype, id, fields string) *map[string]interface{} {
 			if resNum == 1 {
 				res = make(map[string]interface{})
 				for _, hit := range searchResult.Hits.Hits {
-					json.Unmarshal(*hit.Source, &res)
+					b, _ := hit.Source.MarshalJSON()
+					d := json.NewDecoder(bytes.NewBuffer(b))
+					d.UseNumber()
+					d.Decode(&res)
+					//json.Unmarshal(*hit.Source, &res)
 				}
 				return &res
 			}
@@ -422,45 +433,48 @@ func GetByIdField(index, itype, id, fields string) *map[string]interface{} {
 }
 
 //根据id来查询文档
-func GetById(index, itype string, ids ...string) *[]map[string]interface{} {
-	client := GetEsConn()
-	defer DestoryEsConn(client)
-	var res []map[string]interface{}
-	if client != nil {
-		defer func() {
-			if r := recover(); r != nil {
-				log.Println("[E]", r)
-				for skip := 1; ; skip++ {
-					_, file, line, ok := runtime.Caller(skip)
-					if !ok {
-						break
-					}
-					go log.Printf("%v,%v\n", file, line)
-				}
-			}
-		}()
-		query := es.NewIdsQuery().Ids(ids...)
-		searchResult, err := client.Search().Index(index).Type(itype).Query(&query).Do()
-		if err != nil {
-			log.Println("从ES查询出错", err.Error())
-			return nil
-		}
-
-		if searchResult.Hits != nil {
-			resNum := len(searchResult.Hits.Hits)
-			if resNum < 5000 {
-				res = make([]map[string]interface{}, resNum)
-				for i, hit := range searchResult.Hits.Hits {
-					json.Unmarshal(*hit.Source, &res[i])
-				}
-			} else {
-				log.Println("查询结果太多,查询到:", resNum, "条")
-			}
-
-		}
-	}
-	return &res
-}
+//func GetById(index, itype string, ids ...string) *[]map[string]interface{} {
+//	client := GetEsConn()
+//	defer DestoryEsConn(client)
+//	var res []map[string]interface{}
+//	if client != nil {
+//		defer func() {
+//			if r := recover(); r != nil {
+//				log.Println("[E]", r)
+//				for skip := 1; ; skip++ {
+//					_, file, line, ok := runtime.Caller(skip)
+//					if !ok {
+//						break
+//					}
+//					go log.Printf("%v,%v\n", file, line)
+//				}
+//			}
+//		}()
+//		query := es.NewIdsQuery().Ids(ids...)
+//		searchResult, err := client.Search().Index(index).Query(&query).Do(context.Background())
+//		if err != nil {
+//			log.Println("从ES查询出错", err.Error())
+//			return nil
+//		}
+//
+//		if searchResult.Hits != nil {
+//			resNum := len(searchResult.Hits.Hits)
+//			if resNum < 5000 {
+//				res = make([]map[string]interface{}, resNum)
+//				for i, hit := range searchResult.Hits.Hits {
+//					b, _ := hit.Source.MarshalJSON()
+//					d := json.NewDecoder(bytes.NewBuffer(b))
+//					d.Decode(&res[i])
+//					//json.Unmarshal(*hit.Source, &res[i])
+//				}
+//			} else {
+//				log.Println("查询结果太多,查询到:", resNum, "条")
+//			}
+//
+//		}
+//	}
+//	return &res
+//}
 
 //删除某个索引,根据查询
 func Del(index, itype string, query interface{}) bool {
@@ -482,7 +496,7 @@ func Del(index, itype string, query interface{}) bool {
 		}()
 		var err error
 		if qi, ok2 := query.(es.Query); ok2 {
-			_, err = client.DeleteByQuery().Index(index).Type(itype).Query(qi).Do()
+			_, err = client.DeleteByQuery().Index(index).Query(qi).Do(context.Background())
 		}
 		if err != nil {
 			log.Println("删除索引出错:", err.Error())
@@ -494,90 +508,90 @@ func Del(index, itype string, query interface{}) bool {
 }
 
 //根据语句更新对象
-func Update(index, itype, id string, updateStr string) bool {
-	client := GetEsConn()
-	defer DestoryEsConn(client)
-	b := false
-	if client != nil {
-		defer func() {
-			if r := recover(); r != nil {
-				log.Println("[E]", r)
-				for skip := 1; ; skip++ {
-					_, file, line, ok := runtime.Caller(skip)
-					if !ok {
-						break
-					}
-					go log.Printf("%v,%v\n", file, line)
-				}
-			}
-		}()
-		var err error
-		_, err = client.Update().Index(index).Type(itype).Id(id).Script(updateStr).ScriptLang("groovy").Do()
-		if err != nil {
-			log.Println("更新检索出错:", err.Error())
-		} else {
-			b = true
-		}
-	}
-	return b
-}
-
-func BulkUpdate(index, itype string, ids []string, updateStr string) {
-	client := GetEsConn()
-	defer DestoryEsConn(client)
-	if client != nil {
-		defer func() {
-			if r := recover(); r != nil {
-				log.Println("[E]", r)
-				for skip := 1; ; skip++ {
-					_, file, line, ok := runtime.Caller(skip)
-					if !ok {
-						break
-					}
-					go log.Printf("%v,%v\n", file, line)
-				}
-			}
-		}()
-		for _, id := range ids {
-			_, err := client.Update().Index(index).Type(itype).Id(id).Script(updateStr).ScriptLang("groovy").Do()
-			if err != nil {
-				log.Println("更新检索出错:", err.Error())
-			}
-		}
-	}
-}
-
-func BulkUpdateArr(index, itype string, update []map[string]string) {
-	client := GetEsConn()
-	defer DestoryEsConn(client)
-	if client != nil {
-		defer func() {
-			if r := recover(); r != nil {
-				log.Println("[E]", r)
-				for skip := 1; ; skip++ {
-					_, file, line, ok := runtime.Caller(skip)
-					if !ok {
-						break
-					}
-					go log.Printf("%v,%v\n", file, line)
-				}
-			}
-		}()
-		for _, data := range update {
-			id := data["id"]
-			updateStr := data["updateStr"]
-			if id != "" && updateStr != "" {
-				_, err := client.Update().Index(index).Type(itype).Id(id).Script(updateStr).ScriptLang("groovy").Do()
-				if err != nil {
-					log.Println("更新检索出错:", err.Error())
-				}
-			} else {
-				log.Println("数据错误")
-			}
-		}
-
-	}
-}
+//func Update(index, itype, id string, updateStr string) bool {
+//	client := GetEsConn()
+//	defer DestoryEsConn(client)
+//	b := false
+//	if client != nil {
+//		defer func() {
+//			if r := recover(); r != nil {
+//				log.Println("[E]", r)
+//				for skip := 1; ; skip++ {
+//					_, file, line, ok := runtime.Caller(skip)
+//					if !ok {
+//						break
+//					}
+//					go log.Printf("%v,%v\n", file, line)
+//				}
+//			}
+//		}()
+//		var err error
+//		_, err = client.Update().Index(index).Type(itype).Id(id).Script(updateStr).ScriptLang("groovy").Do()
+//		if err != nil {
+//			log.Println("更新检索出错:", err.Error())
+//		} else {
+//			b = true
+//		}
+//	}
+//	return b
+//}
+//
+//func BulkUpdate(index, itype string, ids []string, updateStr string) {
+//	client := GetEsConn()
+//	defer DestoryEsConn(client)
+//	if client != nil {
+//		defer func() {
+//			if r := recover(); r != nil {
+//				log.Println("[E]", r)
+//				for skip := 1; ; skip++ {
+//					_, file, line, ok := runtime.Caller(skip)
+//					if !ok {
+//						break
+//					}
+//					go log.Printf("%v,%v\n", file, line)
+//				}
+//			}
+//		}()
+//		for _, id := range ids {
+//			_, err := client.Update().Index(index).Type(itype).Id(id).Script(updateStr).ScriptLang("groovy").Do()
+//			if err != nil {
+//				log.Println("更新检索出错:", err.Error())
+//			}
+//		}
+//	}
+//}
+//
+//func BulkUpdateArr(index, itype string, update []map[string]string) {
+//	client := GetEsConn()
+//	defer DestoryEsConn(client)
+//	if client != nil {
+//		defer func() {
+//			if r := recover(); r != nil {
+//				log.Println("[E]", r)
+//				for skip := 1; ; skip++ {
+//					_, file, line, ok := runtime.Caller(skip)
+//					if !ok {
+//						break
+//					}
+//					go log.Printf("%v,%v\n", file, line)
+//				}
+//			}
+//		}()
+//		for _, data := range update {
+//			id := data["id"]
+//			updateStr := data["updateStr"]
+//			if id != "" && updateStr != "" {
+//				_, err := client.Update().Index(index).Type(itype).Id(id).Script(updateStr).ScriptLang("groovy").Do()
+//				if err != nil {
+//					log.Println("更新检索出错:", err.Error())
+//				}
+//			} else {
+//				log.Println("数据错误")
+//			}
+//		}
+//
+//	}
+//}
 
 //根据id删除索引对象
 func DelById(index, itype, id string) bool {
@@ -598,7 +612,7 @@ func DelById(index, itype, id string) bool {
 			}
 		}()
 		var err error
-		_, err = client.Delete().Index(index).Type(itype).Id(id).Do()
+		_, err = client.Delete().Index(index).Id(id).Do(context.Background())
 		if err != nil {
 			log.Println("更新检索出错:", err.Error())
 		} else {
@@ -789,7 +803,7 @@ func BulkSave(index, itype string, obj *[]map[string]interface{}, isDelBefore bo
 			}
 			req = req.Add(es.NewBulkIndexRequest().Index(index).Type(itype).Doc(v))
 		}
-		_, err := req.Do()
+		_, err := req.Do(context.Background())
 		if err != nil {
 			log.Println("批量保存到ES出错", err.Error())
 		}
@@ -816,7 +830,7 @@ func Count(index, itype string, query interface{}) int64 {
 		if qi, ok2 := query.(es.Query); ok2 {
 			qq = qi
 		}
-		n, err := client.Count(index).Type(itype).Query(qq).Do()
+		n, err := client.Count(index).Query(qq).Do(context.Background())
 		if err != nil {
 			log.Println("统计出错", err.Error())
 		}
@@ -1094,7 +1108,12 @@ func AnalyzerWord(index, word string) (result []string) {
 	p := url.Values{}
 	p["text"] = []string{word}
 	p["analyzer"] = []string{"ik"}
-	by, err := client.PerformRequest("GET", "/"+index+"/_analyze", p, nil)
+	opt := es.PerformRequestOptions{
+		Method: "GET",
+		Path:   "/" + index + "/_analyze",
+		Body:   p,
+	}
+	by, err := client.PerformRequest(context.Background(), opt)
 	if err != nil {
 		log.Println("AnalyzerWord Error:", err)
 		return

+ 1 - 2
go.mod

@@ -6,14 +6,13 @@ require (
 	github.com/BurntSushi/toml v1.2.0 // indirect
 	github.com/PuerkitoBio/goquery v1.8.0
 	github.com/dchest/captcha v1.0.0
-	github.com/fortytw2/leaktest v1.3.0 // indirect
 	github.com/go-sql-driver/mysql v1.6.0
 	github.com/gomodule/redigo v1.8.9
 	github.com/nsqio/go-nsq v1.1.0
+	github.com/olivere/elastic/v7 v7.0.32
 	go.mongodb.org/mongo-driver v1.10.1
 	go.uber.org/zap v1.22.0
 	gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
 	gopkg.in/natefinch/lumberjack.v2 v2.0.0
-	gopkg.in/olivere/elastic.v2 v2.0.61
 	gopkg.in/yaml.v2 v2.4.0 // indirect
 )

+ 93 - 4
go.sum

@@ -1,26 +1,63 @@
+cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
+github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
 github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
 github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
 github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U=
 github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI=
 github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c=
 github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA=
+github.com/aws/aws-sdk-go v1.43.21/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
 github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
 github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
+github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
+github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
+github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/dchest/captcha v1.0.0 h1:vw+bm/qMFvTgcjQlYVTuQBJkarm5R0YSsDKhm1HZI2o=
 github.com/dchest/captcha v1.0.0/go.mod h1:7zoElIawLp7GUMLcj54K9kbw+jEyvz2K0FDdRRYhvWo=
+github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
+github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
+github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
+github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
 github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
 github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
+github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
+github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
 github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
 github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
+github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
+github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
+github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
+github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
+github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
+github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
+github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
+github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
+github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
+github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
+github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
 github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
 github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
 github.com/gomodule/redigo v1.8.9 h1:Sl3u+2BI/kk+VEatbj0scLdrFhjPmbxOc1myhDP41ws=
 github.com/gomodule/redigo v1.8.9/go.mod h1:7ArFNvsTjH8GMMzB4uy1snslv2BwmginuMs06a1uzZE=
-github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
+github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
+github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
+github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
+github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
+github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
+github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
+github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
+github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
+github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
 github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
 github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
 github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
@@ -28,15 +65,24 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
 github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
 github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
 github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
+github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
+github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
 github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
 github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
 github.com/nsqio/go-nsq v1.1.0 h1:PQg+xxiUjA7V+TLdXw7nVrJ5Jbl3sN86EhGCQj4+FYE=
 github.com/nsqio/go-nsq v1.1.0/go.mod h1:vKq36oyeVXgsS5Q8YEO7WghqidAVXQlcFxzQbQTuDEY=
+github.com/olivere/elastic/v7 v7.0.32 h1:R7CXvbu8Eq+WlsLgxmKVKPox0oOwAE/2T9Si5BnvK6E=
+github.com/olivere/elastic/v7 v7.0.32/go.mod h1:c7PVmLe3Fxq77PIfY/bZmxY/TAamBhCzZ8xDOE09a9k=
+github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
 github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
+github.com/smartystreets/assertions v1.1.1/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
+github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM=
+github.com/smartystreets/gunit v1.4.2/go.mod h1:ZjM1ozSIMJlAz/ay4SG8PeKF00ckUp+zMHZXV9/bvak=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
@@ -55,6 +101,9 @@ github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7Jul
 github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
 go.mongodb.org/mongo-driver v1.10.1 h1:NujsPveKwHaWuKUer/ceo9DzEe7HIj1SlJ6uvXZG0S4=
 go.mongodb.org/mongo-driver v1.10.1/go.mod h1:z4XpeoU6w+9Vht+jAFyLgVrD+jGSQQe0+CBWFHNiHt8=
+go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
+go.opentelemetry.io/otel v1.5.0/go.mod h1:Jm/m+rNp/z0eqJc74H7LPwQ3G87qkU/AnnAydAjSAHk=
+go.opentelemetry.io/otel/trace v1.5.0/go.mod h1:sq55kfhjXYr1zVSyexg0w1mpa03AYXR5eyTkB9NPPdE=
 go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
 go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
 go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
@@ -65,35 +114,55 @@ go.uber.org/zap v1.22.0 h1:Zcye5DUgBloQ9BaT4qc9BnjOFog5TvBSAGkJ3Nf70c0=
 go.uber.org/zap v1.22.0/go.mod h1:H4siCOZOrAolnUPJEkfaSjDqyP+BDS0DdDWzwcgt3+U=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
 golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
 golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
+golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
+golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
+golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
+golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
 golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
 golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
 golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
 golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
 golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
-golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
 golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
+golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
+golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
+golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
+golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
+golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
 golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
 golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
+golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
 golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -101,6 +170,25 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T
 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
+google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
+google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
+google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
+google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
+google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
+google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
+google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
+google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
+google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
+google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
+google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
+google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
+google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
+google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
+google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
+google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
+google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
+google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
@@ -108,10 +196,11 @@ gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 h1:VpOs+IwYnYBaFnrNAeB8UUWtL3
 gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
 gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
 gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
-gopkg.in/olivere/elastic.v2 v2.0.61 h1:7cpl3MW8ysa4GYFBXklpo5mspe4NK0rpZTdyZ+QcD4U=
-gopkg.in/olivere/elastic.v2 v2.0.61/go.mod h1:CTVyl1gckiFw1aLZYxC00g3f9jnHmhoOKcWF7W3c6n4=
+gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
 gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
+honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

+ 0 - 2
mysqldb/mysql.go

@@ -388,7 +388,6 @@ func (m *Mysql) UpdateByTx(tx *sql.Tx, tableName string, query, update map[strin
 		values = append(values, v)
 	}
 	q := fmt.Sprintf("update %s set %s where %s", tableName, strings.Join(q_fs, ","), strings.Join(u_fs, " and "))
-	log.Println(q, values)
 	return m.UpdateOrDeleteBySqlByTx(tx, q, values...) >= 0
 }
 
@@ -476,7 +475,6 @@ func (m *Mysql) Count(tableName string, query map[string]interface{}) int64 {
 	if len(query) > 0 {
 		q += fmt.Sprintf(" where %s", strings.Join(fields, " and "))
 	}
-	log.Println(q, values)
 	return m.CountBySql(q, values...)
 }
 func (m *Mysql) CountBySql(q string, args ...interface{}) int64 {