From f88a44f58396fb36a979cfe5640a36d6ac2d7289 Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期四, 25 七月 2019 14:50:56 +0800 Subject: [PATCH] add discovery --- controllers/esSearch.go | 28 ++++++++++++++++++++-------- 1 files changed, 20 insertions(+), 8 deletions(-) diff --git a/controllers/esSearch.go b/controllers/esSearch.go index f55fff7..971857d 100644 --- a/controllers/esSearch.go +++ b/controllers/esSearch.go @@ -111,17 +111,28 @@ isCollectStr = "{\"term\":{\"isCollect\":\"" + isCollect + "\"}}," } //鍒ゆ柇甯冮槻绛夌骇id - alarmLevelId :=searchBody["alarmlevel"].([]interface{}) + alarmLevelId :=searchBody["alarmlevel"].([]int) alarmLevelStr := "" - if alarmLevelId != nil && alarmLevelId != 0{ - if alarmLevelId != -1 { - id := strings.Replace(strings.Trim(fmt.Sprint(getAlarmLevel(alarmLevel)), "[]"), " ", "\",\"", -1) - alarmLevelStr = "{\"terms\":{\"alarmRules.alarmLevel\":[\"" + id + "\"]}},{\"term\":{\"alarmRules.defenceState\":true}}," - }else{ - alarmLevelStr = "{\"term\":{\"alarmRules.defenceState\":false}}," + defenceStateStr := "" + if len(alarmLevelId) > 0 { + flag := false + for i,v := range alarmLevelId { + if v == -1 { + alarmLevelId = append(alarmLevelId[:i], alarmLevelId[i+1:]...) + defenceStateStr = "{\"term\":{\"alarmRules.defenceState\":false}}," + flag = true + break + } + } + if len(alarmLevelId) > 0{ + if flag == false { + defenceStateStr = "{\"term\":{\"alarmRules.defenceState\":true}}," + } + id := strings.Replace(strings.Trim(fmt.Sprint(getAlarmLevel(alarmLevelId)), "[]"), " ", "\",\"", -1) + alarmLevelStr = "{\"terms\":{\"alarmRules.alarmLevel\":[\"" + id + "\"]}}," } } - + //浣跨敤es搴曞眰鏈哄埗澶勭悊鍒嗛〉 //璇锋眰澶� url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + @@ -137,6 +148,7 @@ "\"filter\":[" + cameraIdStr + alarmLevelStr + + defenceStateStr + taskIdStr + isCollectStr + esTableIdStr + -- Gitblit v1.8.0