Browse Source

Es 添加关闭日志文件

xingzai 3 years ago
parent
commit
ba85db2e3b
1 changed files with 2 additions and 0 deletions
  1. 2 0
      services/elastic.go

+ 2 - 0
services/elastic.go

@@ -29,6 +29,7 @@ func NewClient() (client *elastic.Client, err error) {
 		elastic.SetBasicAuth(ES_USERNAME, ES_PASSWORD),
 		elastic.SetTraceLog(log.New(logFile, "ES-TRACE: ", 0)),
 		elastic.SetSniff(false), elastic.SetErrorLog(errorlog))
+	defer logFile.Close()
 	return
 }
 
@@ -89,6 +90,7 @@ func EsAddOrEditData(indexName, docId string, item *ElasticTestArticleDetail) (e
 		} else {
 			fmt.Println("EditData", resp.Status, resp.Result)
 		}
+		client.CloseIndex(indexName)
 	} else {
 		resp, err := client.Index().Index(indexName).Id(docId).BodyJson(item).Do(context.Background())
 		if err != nil {