|
@@ -7,28 +7,30 @@ import (
|
|
|
"github.com/olivere/elastic/v7"
|
|
|
"hongze/hongze_cygx/models"
|
|
|
"hongze/hongze_cygx/utils"
|
|
|
- "log"
|
|
|
- "os"
|
|
|
"sort"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
func NewClient() (client *elastic.Client, err error) {
|
|
|
- errorlog := log.New(os.Stdout, "APP", log.LstdFlags)
|
|
|
- file := ""
|
|
|
- if utils.RunMode == "release" {
|
|
|
- //file = `/data/rdlucklog/hongze_cygx/eslog.log`
|
|
|
- file = `./rdlucklog/eslog.log`
|
|
|
- } else {
|
|
|
- file = `./rdlucklog/eslog.log`
|
|
|
- }
|
|
|
- logFile, _ := os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766)
|
|
|
+ //errorlog := log.New(os.Stdout, "APP", log.LstdFlags)
|
|
|
+ //file := ""
|
|
|
+ //if utils.RunMode == "release" {
|
|
|
+ // //file = `/data/rdlucklog/hongze_cygx/eslog.log`
|
|
|
+ // file = `./rdlucklog/eslog.log`
|
|
|
+ //} else {
|
|
|
+ // file = `./rdlucklog/eslog.log`
|
|
|
+ //}
|
|
|
+ //logFile, _ := os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766)
|
|
|
+ //client, err = elastic.NewClient(
|
|
|
+ // elastic.SetURL(ES_URL),
|
|
|
+ // elastic.SetBasicAuth(ES_USERNAME, ES_PASSWORD),
|
|
|
+ // elastic.SetTraceLog(log.New(logFile, "ES-TRACE: ", 0)),
|
|
|
+ // elastic.SetSniff(false), elastic.SetErrorLog(errorlog))
|
|
|
client, err = elastic.NewClient(
|
|
|
elastic.SetURL(ES_URL),
|
|
|
elastic.SetBasicAuth(ES_USERNAME, ES_PASSWORD),
|
|
|
- elastic.SetTraceLog(log.New(logFile, "ES-TRACE: ", 0)),
|
|
|
- elastic.SetSniff(false), elastic.SetErrorLog(errorlog))
|
|
|
+ elastic.SetSniff(false))
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -89,6 +91,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 {
|