|
@@ -11,6 +11,7 @@ import (
|
|
|
"os"
|
|
|
"sort"
|
|
|
"strconv"
|
|
|
+ "strings"
|
|
|
)
|
|
|
|
|
|
func NewClient() (client *elastic.Client, err error) {
|
|
@@ -63,10 +64,11 @@ func EsAddOrEditData(indexName, docId string, item *ElasticArticleDetail) (err e
|
|
|
return
|
|
|
}
|
|
|
searchById, err := client.Get().Index(indexName).Id(docId).Do(context.Background())
|
|
|
- if err != nil {
|
|
|
+ if err != nil && !strings.Contains(err.Error(), "404") {
|
|
|
+ fmt.Println("Get Err" + err.Error())
|
|
|
return
|
|
|
}
|
|
|
- if searchById.Found {
|
|
|
+ if searchById != nil && searchById.Found {
|
|
|
resp, err := client.Update().Index(indexName).Id(docId).Doc(map[string]interface{}{
|
|
|
"BodyText": item.BodyText,
|
|
|
"Title": item.Title,
|
|
@@ -83,10 +85,12 @@ func EsAddOrEditData(indexName, docId string, item *ElasticArticleDetail) (err e
|
|
|
} else {
|
|
|
resp, err := client.Index().Index(indexName).Id(docId).BodyJson(item).Do(context.Background())
|
|
|
if err != nil {
|
|
|
+ fmt.Println("新增失败:",err.Error())
|
|
|
return err
|
|
|
}
|
|
|
if resp.Status == 0 && resp.Result == "created" {
|
|
|
fmt.Println("新增成功")
|
|
|
+ err = nil
|
|
|
} else {
|
|
|
fmt.Println("AddData", resp.Status, resp.Result)
|
|
|
}
|
|
@@ -453,7 +457,6 @@ func EsMultiMatchFunctionScoreQuery(indexName, keyWord string, startSize, pageSi
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-
|
|
|
func GetWeight(length int) []int {
|
|
|
steep := 10
|
|
|
intArr := make([]int, 0)
|
|
@@ -480,3 +483,12 @@ func GetArrSum(intArr []int) (sum int) {
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+//func init() {
|
|
|
+// fmt.Println("start")
|
|
|
+// keyWord:="阿里巴巴"
|
|
|
+// keyWordArr, _ := GetIndustryMapNameSliceV2(keyWord)
|
|
|
+// keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
|
|
|
+// fmt.Println(keyWordArr)
|
|
|
+// fmt.Println("end")
|
|
|
+//}
|