Browse Source

feat:增加方法

wangchuanjin 1 year ago
parent
commit
0a4c7f152a
1 changed files with 15 additions and 2 deletions
  1. 15 2
      service/clue.go

+ 15 - 2
service/clue.go

@@ -152,8 +152,8 @@ func CreateEs(v map[string]interface{}) (string, bool) {
 	client := esV7.GetEsConn()
 	defer esV7.DestoryEsConn(client)
 	newId := common.ObjToString(v["id_new"])
-	client.Delete().Index("ttbid").Id(newId).Do(context.TODO())
-	_, err := client.Index().Index("ttbid").Id(newId).BodyJson(v).Do(context.TODO())
+	client.Delete().Index("ttbid").Id(newId).Refresh("true").Do(context.TODO())
+	_, err := client.Index().Index("ttbid").Id(newId).BodyJson(v).Refresh("true").Do(context.TODO())
 	if err != nil {
 		log.Println("保存到ES出错", err.Error())
 		return details, false
@@ -162,6 +162,19 @@ func CreateEs(v map[string]interface{}) (string, bool) {
 	}
 }
 
+//
+func DelById(index, id string) bool {
+	esV7 := Es.(*es.EsV7)
+	client := esV7.GetEsConn()
+	defer esV7.DestoryEsConn(client)
+	_, err := client.Delete().Index(index).Id(id).Refresh("true").Do(context.TODO())
+	if err != nil {
+		log.Println("删除es出错:", id, err)
+		return false
+	}
+	return true
+}
+
 func cleanHTML(htmlString string) string {
 	// 清理HTML标签
 	htmlRegex := regexp.MustCompile("<[^>]*>")