sunty
2019-09-28 f9fc7972b2fb1afa3c3eaef71efa883499b2716f
EsClient.go
@@ -16,7 +16,7 @@
func Parsesources(sources []map[string]interface{}) (esinfos []*protomsg.Esinfo) {
    var ok bool
    for _, source := range sources {
       var tmpinfo protomsg.Esinfo
        tmpinfo := protomsg.Esinfo{}
        tmpinfo.FaceFeature, ok =   source["faceFeature"].(string)
        if !ok {
            continue
@@ -58,8 +58,9 @@
func Videopersonsbyid(sources []map[string]interface{}) (tmpinfos []protomsg.Videopersons) {
    var ok bool
    var tmpinfo protomsg.Videopersons
    //var tmpinfo protomsg.Videopersons
    for _, source := range  sources{
        tmpinfo := protomsg.Videopersons{}
        tmpinfo.Id, ok =   source["id"].(string)
        if !ok {
            continue
@@ -211,8 +212,9 @@
func Dbpersonbyid(sources []map[string]interface{}) (tmpinfos []protomsg.Dbperson) {
        var ok bool
        var tmpinfo protomsg.Dbperson
        //var tmpinfo protomsg.Dbperson
        for _, source := range  sources{
            tmpinfo := protomsg.Dbperson{}
            tmpinfo.FaceFeature, ok =   source["faceFeature"].(string)
            if !ok {
                continue
@@ -279,9 +281,9 @@
func Dbtablebyid(sources []map[string]interface{}) (tmpinfos []protomsg.Dbtable) {
    var ok bool
    var tmpinfo protomsg.Dbtable
    //var tmpinfo protomsg.Dbtable
    for _, source := range  sources{
        tmpinfo := protomsg.Dbtable{}
        tmpinfo.Id, ok    =   source["id"].(string)
        if !ok {
            continue
@@ -357,6 +359,45 @@
    }
    return sources,nil
}
//slice scroll 解析工具函数
func Sourcelistforscroll(buf []byte)(datasource map[string]interface{}, err error){
   var data = make(map[string]interface{})
   var info interface{}
   json.Unmarshal(buf, &info)
   out, ok := info.(map[string]interface{})
   if !ok {
      return nil, errors.New("http response interface can not change map[string]interface{}")
   }
   scroll_id, ok := out["_scroll_id"].(string)
   if !ok {
      return nil, errors.New("first hits change error!")
   }
   //fmt.Println("middle: ",scroll_id)
   middle, ok := out["hits"].(map[string]interface{})
   //fmt.Println("middle: ",out)
   if !ok {
      return nil, errors.New("first hits change error!")
   }
   var sources  = make([]map[string]interface{},0)
   for _, in := range middle["hits"].([]interface{}){
      tmpbuf, ok := in.(map[string]interface{})
      if !ok {
         fmt.Println("change to source error!")
         continue
      }
      source, ok := tmpbuf["_source"].(map[string]interface{})
      if !ok {
         fmt.Println("change _source error!")
         continue
      }
      sources  = append(sources, source )
   }
   data["sourcelist"] = sources
   data["scroll_id"] = scroll_id
   return data,nil
}
func EsReq(method string, url string, parama []byte) (buf []byte, err error) {
    defer elapsed("page")()