|
@@ -641,6 +641,45 @@ func UpdateNewDoc(index, itype string, obj ...interface{}) bool {
|
|
return b
|
|
return b
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func UpdateNew(index string, obj ...interface{}) bool {
|
|
|
|
+ client := GetEsConn()
|
|
|
|
+ defer DestoryEsConn(client)
|
|
|
|
+ b := false
|
|
|
|
+ if client != nil {
|
|
|
|
+ defer func() {
|
|
|
|
+ if r := recover(); r != nil {
|
|
|
|
+ log.Println("[E]", r)
|
|
|
|
+ for skip := 1; ; skip++ {
|
|
|
|
+ _, file, line, ok := runtime.Caller(skip)
|
|
|
|
+ if !ok {
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ go log.Printf("%v,%v\n", file, line)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+ var err error
|
|
|
|
+ for _, v := range obj {
|
|
|
|
+ tempObj := objToMap(v)
|
|
|
|
+ if tempObj == nil || len(*tempObj) == 0 {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ _id := fmt.Sprint((*tempObj)["_id"])
|
|
|
|
+ if _id != "" {
|
|
|
|
+ client.Delete().Index(index).Id(_id).Do(context.TODO())
|
|
|
|
+ }
|
|
|
|
+ _, err = client.Index().Index(index).Id(_id).BodyJson(tempObj).Do(context.TODO())
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Println("保存到ES出错", err.Error())
|
|
|
|
+ } else {
|
|
|
|
+ b = true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return b
|
|
|
|
+}
|
|
|
|
+
|
|
func BulkSave(index, itype string, obj *[]map[string]interface{}, isDelBefore bool) {
|
|
func BulkSave(index, itype string, obj *[]map[string]interface{}, isDelBefore bool) {
|
|
client := GetEsConn()
|
|
client := GetEsConn()
|
|
defer DestoryEsConn(client)
|
|
defer DestoryEsConn(client)
|