From fd27b9cbd159afe5cf5fa57ac66a3403c8cb559e Mon Sep 17 00:00:00 2001 From: sunty <1172534965@qq.com> Date: 星期四, 21 十一月 2019 14:07:11 +0800 Subject: [PATCH] fix initcapinfo --- EsApi.go | 50 +++++++++++++++++++++----------------------------- 1 files changed, 21 insertions(+), 29 deletions(-) diff --git a/EsApi.go b/EsApi.go index 6061321..5d02530 100644 --- a/EsApi.go +++ b/EsApi.go @@ -294,34 +294,34 @@ } //鍒濆鍖栧疄鏃舵姄鎷� -func InitRealTimeCapture(serverIp string, serverPort string, indexName string, isAlarm bool, quantity int) ([]protomsg.AIOcean, error) { +func InitRealTimeCapture(serverIp string, serverPort string, indexName string, isAlarm bool, category string, quantity int) ([]protomsg.AIOcean, error) { var aIOceanInfo []protomsg.AIOcean url := "http://" + serverIp + ":" + serverPort + "/" + indexName + "/_search" - queryStr := "" - if isAlarm == true { - queryStr = `"query":{ - "match_all":{} - },` - } else { - queryStr = `"query":{ + queryStr := `"query":{ "bool":{ "filter":[ { "term":{ - "isAlarm":true + "isAlarm":`+strconv.FormatBool(isAlarm)+` + } + }, + { + "term":{ + "targetInfo.targetType":"`+category+`" } } ] } },` - } + DSLJson := `{ "size":` + strconv.Itoa(quantity) + `, ` + queryStr + ` "sort":[{"picDate":{"order":"desc"}}], "_source": {"includes":[],"excludes":["*.feature"]} }` + fmt.Println(DSLJson) buf, err := EsReq("POST", url, []byte(DSLJson)) if err != nil { return aIOceanInfo, err @@ -342,18 +342,6 @@ var aIOceanInfo []protomsg.AIOcean url := "http://" + serverIp + ":" + serverPort + "/" + indexName + "/_search" - queryStr := "" - if isAlarm == true { - fmt.Println("continue") - } else { - queryStr = ` - { - "term":{ - "isAlarm":1 - } - } - ` - } DSLJson := `{ "size":20, "query":{ @@ -367,11 +355,15 @@ } } }, - ` + queryStr + ` + { + "term":{ + "isAlarm":`+strconv.FormatBool(isAlarm)+` + } + } ] } }, - "_source": ["baseInfo", "alarmRules", "sex", "analyServerName", "sdkName", "ageDescription", "content", "id", "cameraAddr", "picMaxUrl", "picDate", "race", "videoUrl", "picSmUrl", "taskName", "personIsHub", "isAlarm", "analyServerIp", "cameraId", "isAckAlarm"] + "_source": {"includes":[],"excludes":["*.feature"]} }` buf, err := EsReq("POST", url, []byte(DSLJson)) @@ -391,10 +383,6 @@ //缁煎悎缁熻 func StatisticsComprehensive(serverIp string, serverPort string, indexName string, isAlarm bool) (total int, err error) { - isAlarmStr := "" - if isAlarm == true { - isAlarmStr = `,{"term":{"isAlarm":true}}` - } url := "http://" + serverIp + ":" + serverPort + "/" + indexName + "/_search" DSLJson := `{ @@ -407,8 +395,12 @@ "gte":"now+8h/d" } } + }, + { + "term":{ + "isAlarm":`+strconv.FormatBool(isAlarm)+` + } } - ` + isAlarmStr + ` ] } } -- Gitblit v1.8.0