Jianghan vor 2 Jahren
Ursprung
Commit
ee2add33ba
1 geänderte Dateien mit 6 neuen und 6 gelöschten Zeilen
  1. 6 6
      elastic/elasticSim.go

+ 6 - 6
elastic/elasticSim.go

@@ -37,7 +37,7 @@ func (e *Elastic) InitElasticSize() {
 	}
 }
 
-//关闭连接
+// 关闭连接
 func (e *Elastic) DestoryEsConn(client *es.Client) {
 	select {
 	case e.Pool <- client:
@@ -85,7 +85,7 @@ func (e *Elastic) GetEsConn() *es.Client {
 	}
 }
 
-func (e *Elastic) Get(index, query string) *[]map[string]interface{} {
+func (e *Elastic) Get(index string, query es.Query) *[]map[string]interface{} {
 	client := e.GetEsConn()
 	defer func() {
 		go e.DestoryEsConn(client)
@@ -104,7 +104,7 @@ func (e *Elastic) Get(index, query string) *[]map[string]interface{} {
 				}
 			}
 		}()
-		searchResult, err := client.Search().Index(index).Source(query).Do(context.Background())
+		searchResult, err := client.Search().Index(index).Query(query).Do(context.Background())
 		if err != nil {
 			log.Println("从ES查询出错", err.Error())
 			return nil
@@ -127,7 +127,7 @@ func (e *Elastic) Get(index, query string) *[]map[string]interface{} {
 	return &res
 }
 
-//关闭elastic
+// 关闭elastic
 func (e *Elastic) Close() {
 	for i := 0; i < e.I_size; i++ {
 		cli := <-e.Pool
@@ -180,7 +180,7 @@ func (e *Elastic) BulkSave(index string, obj []map[string]interface{}) {
 	}
 }
 
-//根据id删除索引对象
+// 根据id删除索引对象
 func (e *Elastic) DelById(index, id string) bool {
 	client := e.GetEsConn()
 	defer e.DestoryEsConn(client)
@@ -420,7 +420,7 @@ func (e *Elastic) DeleteBulk(index string, ids []string) {
 	}
 }
 
-//InsertOrUpdate 插入或更新
+// InsertOrUpdate 插入或更新
 func (e *Elastic) InsertOrUpdate(index string, docs []map[string]interface{}) error {
 	client := e.GetEsConn()
 	defer e.DestoryEsConn(client)