From bae7a9a30b89c519460746cfa19cd7e66a0196e2 Mon Sep 17 00:00:00 2001 From: sunty <1172534965@qq.com> Date: 星期日, 19 一月 2020 17:13:07 +0800 Subject: [PATCH] update _source list and struct --- controllers/esSearch.go | 37 ++++++++++++++++++++++--------------- 1 files changed, 22 insertions(+), 15 deletions(-) diff --git a/controllers/esSearch.go b/controllers/esSearch.go index 314ef31..5eac425 100644 --- a/controllers/esSearch.go +++ b/controllers/esSearch.go @@ -34,8 +34,8 @@ var arg models.EsSearch err := c.BindJSON(&arg) - if err !=nil || arg.Page <=0 && arg.Size<=0 { - util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎") + if err != nil || arg.Page <= 0 && arg.Size <= 0 { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎") return } data := findEsData(&arg) @@ -105,7 +105,7 @@ //鍒ゆ柇鏁版嵁ID idStr := "" - linkTagInfoIdStr :="" + linkTagInfoIdStr := "" //personId := searchBody.Id id := []string{} if id != nil && len(id) > 0 { @@ -158,14 +158,14 @@ linkTagInfoAlarmLevelStr := "" if len(alarmLevelId) > 0 { alarmLevelTypes := strings.Replace(strings.Trim(fmt.Sprint(getAlarmLevel(alarmLevelId)), "[]"), " ", "\",\"", -1) - alarmLevelStr = "{\"terms\":{\"alarmRules.alarmLevel\":[\"" + alarmLevelTypes + "\"]}}," - linkTagInfoAlarmLevelStr = "{\"terms\":{\"linkTagInfo.alarmRules.alarmLevel\":[\"" + alarmLevelTypes + "\"]}}," + alarmLevelStr = "{\"terms\":{\"alarmRules.alarmLevel.raw\":[\"" + alarmLevelTypes + "\"]}}," + linkTagInfoAlarmLevelStr = "{\"terms\":{\"linkTagInfo.alarmRules.alarmLevel.raw\":[\"" + alarmLevelTypes + "\"]}}," } //浣跨敤es搴曞眰鏈哄埗澶勭悊鍒嗛〉 //璇锋眰澶� localConf, err2 := cache.GetServerInfo() - if err2 !=nil || localConf.AlarmIp == "" || localConf.ServerId == "" { + if err2 != nil || localConf.AlarmIp == "" || localConf.ServerId == "" { logger.Debug("localConfig is wrong!!!") return nil } @@ -188,7 +188,7 @@ isCollectStr + esTableIdStr + analyServerFilterStr + - "{\"range\":{\"picDate\":{\"from\":\"" + gteDate + "\",\"to\":\"" + lteDate + "\",\"include_lower\":true,\"include_upper\":true,\"boost\":1}}}"+ + "{\"range\":{\"picDate\":{\"from\":\"" + gteDate + "\",\"to\":\"" + lteDate + "\",\"include_lower\":true,\"include_upper\":true,\"boost\":1}}}" + "]}}," + "{\"bool\":{\"filter\":[" + linkTagInfoCameraIdStr + @@ -198,13 +198,13 @@ linkTagInfoIsCollectStr + linkTagInfoEsTableIdStr + linkTagInfoAnalyServerFilterStr + - "{\"range\":{\"linkTagInfo.picDate\":{\"from\":\"" + gteDate + "\",\"to\":\"" + lteDate + "\",\"include_lower\":true,\"include_upper\":true,\"boost\":1}}}"+ + "{\"range\":{\"linkTagInfo.picDate\":{\"from\":\"" + gteDate + "\",\"to\":\"" + lteDate + "\",\"include_lower\":true,\"include_upper\":true,\"boost\":1}}}" + "]}}" + - "]," + - "\"sort\":[{\"_score\":{\"order\":\"desc\"}},{\"picDate\":{\"order\":\"desc\"}}]," + + "],\"minimum_should_match\":1}}," + + "\"sort\":[{\"_score\":{\"order\":\"desc\"}},{\"updateTime\":{\"order\":\"desc\"}}]," + "\"_source\":{\"includes\":[],\"excludes\":[\"*.feature\"]}" + "}" - logger.Debug("findEsData.param:",prama) + logger.Debug("findEsData.param:", prama) //鏁版嵁瑙f瀽 tokenRes := esutil.GetEsDataReq(url, prama, true) //fmt.Println(tokenRes) @@ -215,30 +215,37 @@ for _, masterInfoValues := range data.([]interface{}) { masterInfo := masterInfoValues.(map[string]interface{}) sources := make(map[string]interface{}, 0) - + activateInfo := make(map[string]interface{}) if masterInfo["linkTagInfo"] != nil { linkTagInfo := masterInfo["linkTagInfo"].([]interface{}) delete(masterInfo, "linkTagInfo") - if len(linkTagInfo) >0 { + if len(linkTagInfo) > 0 { slaveList := make([]interface{}, 0) slaveList = append(slaveList, masterInfo) slaveList = append(slaveList, linkTagInfo...) + for i, j := 0, len(slaveList)-1; i < j; i, j = i+1, j-1 { + slaveList[i], slaveList[j] = slaveList[j], slaveList[i] + } sources["list"] = slaveList + activateInfo = slaveList[0].(map[string]interface{}) } else { sources["list"] = []interface{}{ masterInfo, } + activateInfo = masterInfo } } else { - if _,ok := masterInfo["linkTagInfo"];ok { + if _, ok := masterInfo["linkTagInfo"]; ok { delete(masterInfo, "linkTagInfo") } sources["list"] = []interface{}{ masterInfo, } + activateInfo = masterInfo + } - sources["activeObject"] = masterInfo + sources["activeObject"] = activateInfo tmpDate["datalist"] = append(tmpDate["datalist"], sources) } -- Gitblit v1.8.0