From f9bf85d9f2f834995d4a485054bf5cb6810ad029 Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期四, 20 八月 2020 21:11:12 +0800
Subject: [PATCH] add pic url

---
 EsApi.go |   58 ++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/EsApi.go b/EsApi.go
index 748d4f4..eabf7cf 100644
--- a/EsApi.go
+++ b/EsApi.go
@@ -234,7 +234,7 @@
 		return nil, err
 	}
 
-	sources, err := SourceAggregations(buf,thresholdTime)
+	sources, err := SourceAggregations(buf, thresholdTime)
 	if err != nil {
 		return nil, err
 	}
@@ -243,53 +243,67 @@
 }
 
 //鏍规嵁鎶撴媿浜哄憳id鏇存柊锛坧icurl锛夊浘鐗囧湴鍧�---棰勫紑鍙�
-func UpdatePicUrlById(id string, picurl string, indexName string, serverIp string, serverPort string) (statu int, err error) {
+func UpdatePicUrlById(id string, picUrl string, indexName string, serverIp string, serverPort string) (err error) {
 
+	tRes, err := AIOceaninfosbyid([]string{id}, indexName, serverIp, serverPort)
+	if err != nil || len(tRes) == 0 {
+		return err
+	}
+	picMaxUrls := tRes[0].PicMaxUrl
+	sourceStr := `    	
+        "lang":"painless",
+        "inline": "ctx._source.picMaxUrl.add(` + picUrl + `)"
+`
+	if len(picMaxUrls) >= 2 {
+		sourceStr = `"source": "ctx._source.picMaxUrl[1]='` + picUrl + `'"`
+	}
 	var info interface{}
 	url := "http://" + serverIp + ":" + serverPort + "/" + indexName + "/_update_by_query?refresh=true"
-	sourceStr := "ctx._source.videoUrl='" + picurl + "'"
-	var videoUrlInfo = `
+
+	var picUrlInfo = `
         {
           "script": {
-            "source": "` + sourceStr + `"	
+           ` + sourceStr + `
           },
-          "query": {
-            "term": {
-              "id": "` + id + `"
-            }
-          }
+              "query": {
+    		    "bool": {
+    		        "filter": [
+    		            {
+    		                "term": {
+    		                    "id": "` + id + `"
+    		                }
+    		            }
+    		        ]
+    		    }
+    		}
         }
         `
 	//logPrint("url: ", url, videoUrlInfo)
-	buf, err := EsReq("POST", url, []byte(videoUrlInfo))
+	//fmt.Println(url, picUrlInfo)
+	buf, err := EsReq("POST", url, []byte(picUrlInfo))
 	if err != nil {
 		logPrint("http request videoUrlInfo info is err!")
-		statu = 500
-		return statu, err
+		return err
 	}
 	json.Unmarshal(buf, &info)
 	//logPrint(info)
 	out, ok := info.(map[string]interface{})
 	if !ok {
 		logPrint("http response interface can not change map[string]interface{}")
-		statu = 500
-		return statu, errors.New("http response interface can not change map[string]interface{}")
+		return errors.New("http response interface can not change map[string]interface{}")
 	}
 	middle, ok := out["updated"].(float64)
 	if !ok {
 		logPrint("first updated change error!")
-		statu = 500
-		return statu, errors.New("first updated change error!")
+		return errors.New("first updated change error!")
 	}
 	if middle == 1 {
-		statu = 200
-		return statu, nil
+		return nil
 	}
 	if middle == 0 {
-		statu = 201
-		return statu, errors.New("宸茬粡淇敼")
+		return errors.New("宸茬粡淇敼")
 	}
-	return statu, nil
+	return nil
 }
 
 //鏍规嵁鎶撴媿浜哄憳id鏇存柊锛坴ideourl锛夋憚鍍忔満鍦板潃

--
Gitblit v1.8.0