From 197765640210a617cb9f0b85daf5d4ebe15484ed Mon Sep 17 00:00:00 2001 From: sunty <1172534965@qq.com> Date: 星期四, 25 七月 2019 15:57:08 +0800 Subject: [PATCH] add updateVideourlById --- EsApi.go | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 49 insertions(+), 1 deletions(-) diff --git a/EsApi.go b/EsApi.go index cd9c5b6..122178e 100644 --- a/EsApi.go +++ b/EsApi.go @@ -1,7 +1,8 @@ package esutil import ( - "errors" + "encoding/json" + "errors" "fmt" "strconv" "strings" @@ -169,3 +170,50 @@ } return tablename, nil } + + +//鏍规嵁鎶撴媿浜哄憳id鏇存柊锛坴ideourl锛夋憚鍍忔満鍦板潃 +func updateVideourlById(id string, videoUrl string, indexName string, serverIp string, serverPort string)(statu int){ + var info interface{} + var videoUrlInfo = ` + { + "script": { + "source": "ctx._source.videoUrl='` + videoUrl + `'" + }, + "query": { + "term": { + "id": "` +id+ `" + } + } + } + ` + buf, err := EsReq("POST", "http://"+serverIp+":"+serverPort+"/"+indexName+"/_search",[]byte(videoUrlInfo)) + if err != nil { + fmt.Println("http request videoUrlInfo info is err!") + statu = 500 + return + } + json.Unmarshal(buf, &info) + out, ok := info.(map[string]interface{}) + if !ok { + fmt.Println("http response interface can not change map[string]interface{}") + statu = 500 + return + } + + middle, ok := out["updated"].(int) + if !ok { + fmt.Println("first updated change error!") + statu = 500 + return + } + if middle == 1{ + statu = 200 + return + } + if middle == 0{ + statu = 201 + return + } + return statu +} \ No newline at end of file -- Gitblit v1.8.0