瀏覽代碼

no message

Jianghan 2 年之前
父節點
當前提交
ee2add33ba
共有 1 個文件被更改,包括 6 次插入6 次删除
  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)