From 705f76d542397154da2acf5461f2888828cbd5b8 Mon Sep 17 00:00:00 2001
From: putonghao <ynxwpth@163.com>
Date: 星期三, 14 九月 2022 14:38:55 +0800
Subject: [PATCH] update cluster name to elasticsearch.yml
---
EsApi.go | 59 +++++++++++++++++++++++++++++++++++++++--------------------
1 files changed, 39 insertions(+), 20 deletions(-)
diff --git a/EsApi.go b/EsApi.go
index 96348c7..f690f7d 100644
--- a/EsApi.go
+++ b/EsApi.go
@@ -888,18 +888,25 @@
return statu, errors.New("http response interface can not change map[string]interface{}")
}
middle, ok := out["updated"].(float64)
- if !ok {
+ batches,ok1 := out["batches"].(float64)
+ if !ok || !ok1{
logPrint("first updated change error!")
statu = 500
return statu, errors.New("first updated change error!")
}
- if middle == 1 {
- statu = 200
- return statu, nil
- }
- if middle == 0 {
- statu = 201
- return statu, errors.New("宸茬粡淇敼")
+ if batches == 0 {
+ logPrint("no such doc in database")
+ statu = 400
+ return statu,errors.New("鐩爣鏁版嵁涓嶅瓨鍦�")
+ } else {
+ if middle == 1 {
+ statu = 200
+ return statu, nil
+ }
+ if middle == 0 {
+ statu = 201
+ return statu, errors.New("宸茬粡淇敼")
+ }
}
return statu, nil
}
@@ -944,7 +951,12 @@
isCollectStr := ""
isCollect := compareArgs.Collection
if isCollect != "" {
- isCollectStr = "{\"term\":{\"isCollect\":\"" + isCollect + "\"}},"
+ //isCollectStr = "{\"term\":{\"isCollect\":\"" + isCollect + "\"}},"
+ if isCollect == "1" {
+ isCollectStr = "{\"term\":{\"isCollect\":true}},"
+ } else if isCollect == "0" {
+ isCollectStr = "{\"term\":{\"isCollect\":false}},"
+ }
}
//鍒ゆ柇甯冮槻绛夌骇
@@ -1276,10 +1288,19 @@
}
//鑱氬悎浠诲姟鍒楄〃锛宼askId+taskName
-func AggregateTaskList(serverIp string, serverPort string, indexName string, analyServerId string) (sources []map[string]interface{}, err error) {
+func AggregateTaskList(serverIp string, serverPort string, indexName string, analyServerId string, cameraIds []string) (sources []map[string]interface{}, err error) {
url := "http://" + serverIp + ":" + serverPort +
"/" + indexName + "/_search"
serverFilterStr := ""
+ cameIdFilterStr := ""
+ if cameraIds != nil && len(cameraIds) > 0 {
+ cameIdsStr := strings.Replace(strings.Trim(fmt.Sprint(cameraIds), "[]"), " ", "\",\"", -1)
+ cameIdFilterStr = `,{
+ "term": {
+ "cameraId": "` + cameIdsStr + `"
+ }
+ }`
+ }
if analyServerId != "" {
serverFilterStr = `,
"query": {
@@ -1288,8 +1309,9 @@
{
"term": {
"analyServerId": "` + analyServerId + `"
+ }
}
- }
+ ` + cameIdFilterStr + `
]
}
}`
@@ -1621,7 +1643,7 @@
}
//鎸夋棩鏈熻寖鍥达紝鏈嶅姟鍣↖d鍒犻櫎鏁版嵁
-func DeleteAnalyServerData(serverIp string, serverPort string, indexName string, startTime string, endTime string, analyServerId string) (result bool, err error) {
+func DeleteAnalyServerData(serverIp string, serverPort string, indexName string, startTime string, endTime string, analyServerId string) (total int, err error,) {
url := "http://" + serverIp + ":" + serverPort + "/" + indexName + "/_delete_by_query"
deleteJson := `{
"query":{
@@ -1643,20 +1665,17 @@
}
}
} `
+ fmt.Println(url)
+ fmt.Println(deleteJson)
buf, err := EsReq("POST", url, []byte(deleteJson))
if err != nil {
- return false, errors.New("璇锋眰澶辫触")
+ return -1, errors.New("璇锋眰澶辫触")
}
deleteRes, err := SourceDeleted(buf)
if err != nil {
- return false, errors.New("瑙g爜澶辫触")
+ return -1, errors.New("瑙g爜澶辫触")
}
- if deleteRes == -1 {
- result = false
- } else {
- result = true
- }
- return result, nil
+ return deleteRes,nil
}
//缁欐墍鏈夎妭鐐硅拷鍔犲垹闄や换鍔′俊鎭�
--
Gitblit v1.8.0