sunty
2019-09-25 9969f8072b23fd8d03cb38445a81ae881bd01ee2
EsClient.go
@@ -359,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")()