|
@@ -1,45 +1,48 @@
|
|
|
package public
|
|
|
|
|
|
import (
|
|
|
- elastic2 "app.yhyue.com/moapp/esv1/gopkg.in/olivere/elastic.v1"
|
|
|
- util "app.yhyue.com/moapp/jybase/common"
|
|
|
"app.yhyue.com/moapp/jybase/encrypt"
|
|
|
- elastic "app.yhyue.com/moapp/jybase/esv1"
|
|
|
- "log"
|
|
|
- "runtime"
|
|
|
+ elastic "app.yhyue.com/moapp/jybase/es"
|
|
|
+ esV7 "github.com/olivere/elastic/v7"
|
|
|
)
|
|
|
|
|
|
// GetAggs 聚合查询
|
|
|
-func GetAggs(index, itype, query string) (aggs elastic2.Aggregations, count int64, hist []*elastic2.SearchHit) {
|
|
|
- defer util.Catch()
|
|
|
- client := elastic.GetEsConn()
|
|
|
- defer func() {
|
|
|
- go elastic.DestoryEsConn(client)
|
|
|
- }()
|
|
|
- if client != nil {
|
|
|
- defer func() {
|
|
|
- if r := recover(); r != nil {
|
|
|
- log.Println("[SEARCH-ERR]", r)
|
|
|
- for skip := 1; ; skip++ {
|
|
|
- _, file, line, ok := runtime.Caller(skip)
|
|
|
- if !ok {
|
|
|
- break
|
|
|
- }
|
|
|
- go log.Printf("[SEARCH-INFO]%v,%v\n", file, line)
|
|
|
- }
|
|
|
- }
|
|
|
- }()
|
|
|
- searchResult, err := client.Search().Index(index).Type(itype).Source(query).Do()
|
|
|
- if err != nil {
|
|
|
- log.Println("[SEARCH-ERR]从ES查询出错", err.Error())
|
|
|
- }
|
|
|
- count = searchResult.Hits.TotalHits
|
|
|
- hist = searchResult.Hits.Hits
|
|
|
- aggs = searchResult.Aggregations
|
|
|
- }
|
|
|
- return
|
|
|
+func GetAggs(index, itype, query string) (aggs esV7.Aggregations, count int64, res []map[string]interface{}) {
|
|
|
+ v1, c, v2 := elastic.GetAggs(index, itype, query)
|
|
|
+ return v1, c, v2
|
|
|
}
|
|
|
|
|
|
+// GetAggs 聚合查询
|
|
|
+//func GetAggs_old(index, itype, query string) (aggs elastic2.Aggregations, count int64, hist []*elastic2.SearchHit) {
|
|
|
+// defer util.Catch()
|
|
|
+// client := elastic.GetEsConn()
|
|
|
+// defer func() {
|
|
|
+// go elastic.DestoryEsConn(client)
|
|
|
+// }()
|
|
|
+// if client != nil {
|
|
|
+// defer func() {
|
|
|
+// if r := recover(); r != nil {
|
|
|
+// log.Println("[SEARCH-ERR]", r)
|
|
|
+// for skip := 1; ; skip++ {
|
|
|
+// _, file, line, ok := runtime.Caller(skip)
|
|
|
+// if !ok {
|
|
|
+// break
|
|
|
+// }
|
|
|
+// go log.Printf("[SEARCH-INFO]%v,%v\n", file, line)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }()
|
|
|
+// searchResult, err := client.Search().Index(index).Type(itype).Source(query).Do()
|
|
|
+// if err != nil {
|
|
|
+// log.Println("[SEARCH-ERR]从ES查询出错", err.Error())
|
|
|
+// }
|
|
|
+// count = searchResult.Hits.TotalHits
|
|
|
+// hist = searchResult.Hits.Hits
|
|
|
+// aggs = searchResult.Aggregations
|
|
|
+// }
|
|
|
+// return
|
|
|
+//}
|
|
|
+
|
|
|
// EncodeId 加密
|
|
|
func EncodeId(sid string) string {
|
|
|
if sid == "" {
|