liuxiaolong
2019-10-11 b0500fee9c01e17c81b9293b244c8ed88dc9ca29
controllers/es.go
@@ -1,12 +1,13 @@
package controllers
import (
   "basic.com/dbapi.git"
   "basic.com/valib/logger.git"
   "fmt"
   "github.com/gin-gonic/gin"
   "math/rand"
   "strconv"
   "strings"
   "webserver/cache"
   "webserver/extend/code"
   "webserver/extend/config"
   "webserver/extend/esutil"
@@ -40,18 +41,20 @@
         //二次搜索和排序
         twiceM := GetCompareDataTwice(co,searchBody)
         util.ResponseFormat(c,code.Success,twiceM)
         return
      } else {
         m :=make(map[string]interface{},0)
         m["compareNum"] = searchBody.CompareNum
         m["total"] = 0
         m["totalList"] = []service.CompareResult{}
         m["totalList"] = []CompareResult{}
         util.ResponseFormat(c,code.CompareResultGone,m)
         return
      }
   }
   m :=make(map[string]interface{},0)
   m["compareNum"] = searchBody.CompareNum
   m["total"] = 0
   m["totalList"] = []service.CompareResult{}
   m["totalList"] = []CompareResult{}
   util.ResponseFormat(c,code.CompareResultGone,m)
}
@@ -101,12 +104,15 @@
   esSize := strconv.Itoa(webSize)
   //使用es底层机制处理分页
   //请求头
   url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
   localConf, err2 := cache.GetServerInfo()
   if err2 !=nil || localConf.AlarmIp == "" || localConf.ServerId == "" {
      logger.Debug("localConfig is wrong!!!")
      return nil
   }
   url := "http://" + localConf.AlarmIp + ":" + strconv.Itoa(int(localConf.AlarmPort)) +
      "/" + index + "/_search?search_type=dfs_query_then_fetch"
   var setApi dbapi.SysSetApi
   _, sysconf := setApi.GetServerInfo()
   analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + sysconf.ServerId + "\"}},"
   analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + localConf.ServerId + "\"}},"
   //请求体
   prama := "{\"from\":\"" + esFrom + "\",\"size\":\"" + esSize + "\"," +