aggsSearchUtil.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package public
  2. import (
  3. "app.yhyue.com/moapp/jybase/encrypt"
  4. elastic "app.yhyue.com/moapp/jybase/es"
  5. esV7 "github.com/olivere/elastic/v7"
  6. )
  7. // GetAggs 聚合查询
  8. func GetAggs(index, itype, query string) (aggs esV7.Aggregations, count int64, res []map[string]interface{}) {
  9. v1, c, v2 := elastic.GetAggs(index, itype, query)
  10. return v1, c, v2
  11. }
  12. // GetAggs 聚合查询
  13. //func GetAggs_old(index, itype, query string) (aggs elastic2.Aggregations, count int64, hist []*elastic2.SearchHit) {
  14. // defer util.Catch()
  15. // client := elastic.GetEsConn()
  16. // defer func() {
  17. // go elastic.DestoryEsConn(client)
  18. // }()
  19. // if client != nil {
  20. // defer func() {
  21. // if r := recover(); r != nil {
  22. // log.Println("[SEARCH-ERR]", r)
  23. // for skip := 1; ; skip++ {
  24. // _, file, line, ok := runtime.Caller(skip)
  25. // if !ok {
  26. // break
  27. // }
  28. // go log.Printf("[SEARCH-INFO]%v,%v\n", file, line)
  29. // }
  30. // }
  31. // }()
  32. // searchResult, err := client.Search().Index(index).Type(itype).Source(query).Do()
  33. // if err != nil {
  34. // log.Println("[SEARCH-ERR]从ES查询出错", err.Error())
  35. // }
  36. // count = searchResult.Hits.TotalHits
  37. // hist = searchResult.Hits.Hits
  38. // aggs = searchResult.Aggregations
  39. // }
  40. // return
  41. //}
  42. // EncodeId 加密
  43. func EncodeId(sid string) string {
  44. if sid == "" {
  45. return ""
  46. }
  47. return encrypt.EncodeArticleId2ByCheck(sid)
  48. }
  49. // DecodeId 解密
  50. func DecodeId(eid string) string {
  51. if eid == "" {
  52. return ""
  53. }
  54. return encrypt.DecodeArticleId2ByCheck(eid)[0]
  55. }