|
@@ -1,8 +1,6 @@
|
|
|
package customer
|
|
|
|
|
|
import (
|
|
|
- "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
- "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
"database/sql"
|
|
|
"encoding/json"
|
|
|
"entniche_new/src/config"
|
|
@@ -10,12 +8,14 @@ import (
|
|
|
"fmt"
|
|
|
"log"
|
|
|
"math"
|
|
|
- "runtime"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
- elastic "app.yhyue.com/moapp/jybase/esv1"
|
|
|
+ "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
+ "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
+
|
|
|
+ elastic "app.yhyue.com/moapp/jybase/es"
|
|
|
|
|
|
"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
|
|
@@ -24,8 +24,6 @@ import (
|
|
|
. "app.yhyue.com/moapp/jybase/date"
|
|
|
. "app.yhyue.com/moapp/jypkg/ent/entity"
|
|
|
. "app.yhyue.com/moapp/jypkg/ent/util"
|
|
|
-
|
|
|
- elastic1 "app.yhyue.com/moapp/esv1/gopkg.in/olivere/elastic.v1"
|
|
|
)
|
|
|
|
|
|
const (
|
|
@@ -1043,62 +1041,13 @@ type Bucket struct {
|
|
|
}
|
|
|
|
|
|
// 聚合查询
|
|
|
-func GetAggs(index, itype, query string) (aggs elastic1.Aggregations, res []map[string]interface{}, count int64, msg string) {
|
|
|
+func GetAggs(index, itype, query string) (aggs elastic.Aggregations, res []map[string]interface{}, count int64, msg string) {
|
|
|
count = elastic.Count(index, itype, query)
|
|
|
if count > config.Config.ItemsNumber {
|
|
|
msg = "搜索目标过于宽泛,请缩小搜索范围。"
|
|
|
return
|
|
|
}
|
|
|
- defer qutil.Catch()
|
|
|
- client := elastic.GetEsConn()
|
|
|
- defer func() {
|
|
|
- go elastic.DestoryEsConn(client)
|
|
|
- }()
|
|
|
- if client != nil {
|
|
|
- defer func() {
|
|
|
- if r := recover(); r != nil {
|
|
|
- for skip := 1; ; skip++ {
|
|
|
- _, file, line, ok := runtime.Caller(skip)
|
|
|
- if !ok {
|
|
|
- break
|
|
|
- }
|
|
|
- go log.Printf("%v,%v\n", file, line)
|
|
|
- }
|
|
|
- }
|
|
|
- }()
|
|
|
- searchResult, err := client.Search().Index(index).Type(itype).Source(query).Do()
|
|
|
- if searchResult.TimedOut {
|
|
|
- //请求超时
|
|
|
- log.Println(err, "____________:::", searchResult.TimedOut)
|
|
|
- return
|
|
|
- }
|
|
|
- if err != nil {
|
|
|
- log.Println("从ES查询出错", err.Error())
|
|
|
- }
|
|
|
- aggs = searchResult.Aggregations
|
|
|
- if searchResult.Hits != nil {
|
|
|
- resNum := len(searchResult.Hits.Hits)
|
|
|
- if resNum < 10000 {
|
|
|
- res = make([]map[string]interface{}, resNum)
|
|
|
- for i, hit := range searchResult.Hits.Hits {
|
|
|
- parseErr := json.Unmarshal(*hit.Source, &res[i])
|
|
|
- if parseErr == nil && hit.Highlight != nil && res[i] != nil {
|
|
|
-
|
|
|
- res[i]["highlight"] = map[string][]string(hit.Highlight)
|
|
|
- }
|
|
|
- if hit.Source != nil && res[i] != nil {
|
|
|
- data := map[string]interface{}{}
|
|
|
- dataByte, _ := hit.Source.MarshalJSON()
|
|
|
- json.Unmarshal(dataByte, &data)
|
|
|
- res[i]["source"] = data
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.Println("查询结果太多,查询到:", resNum, "条")
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ aggs, _, res = elastic.GetAggs(index, itype, query)
|
|
|
return
|
|
|
}
|
|
|
|