|
@@ -167,19 +167,21 @@ func Save(index, itype string, obj interface{}) bool {
|
|
|
//{"query":{"filtered":{"query":{"match_all":{}},"filter":{"range":{"balance":{"gte":20000,"lte":30000}}}}}}
|
|
|
//{"query":{"match_all":{}},"from":10,"size":10,"_source":["account_number","balance"],"sort":{"balance":{"order":"desc"}}}
|
|
|
//{"query":{"match_phrase":{"address":"milllane"}}}和match不同会去匹配整个短语,相当于must[]
|
|
|
-func DfsGet(index, itype, query string) *[]map[string]interface{} {
|
|
|
+func DfsGet(index, itype, query string) (int64, *[]map[string]interface{}) {
|
|
|
return get(index, itype, query, "dfs_query_then_fetch")
|
|
|
}
|
|
|
func Get(index, itype, query string) *[]map[string]interface{} {
|
|
|
- return get(index, itype, query, "")
|
|
|
+ _, r := get(index, itype, query, "")
|
|
|
+ return r
|
|
|
}
|
|
|
-func get(index, itype, query, searchType string) *[]map[string]interface{} {
|
|
|
+func get(index, itype, query, searchType string) (int64, *[]map[string]interface{}) {
|
|
|
//log.Println("query -- ", query)
|
|
|
client := GetEsConn()
|
|
|
defer func() {
|
|
|
go DestoryEsConn(client)
|
|
|
}()
|
|
|
var res []map[string]interface{}
|
|
|
+ var total int64
|
|
|
if client != nil {
|
|
|
defer func() {
|
|
|
if r := recover(); r != nil {
|
|
@@ -200,9 +202,9 @@ func get(index, itype, query, searchType string) *[]map[string]interface{} {
|
|
|
searchResult, err := ss.Do(context.TODO())
|
|
|
if err != nil {
|
|
|
log.Println("从ES查询出错", err.Error())
|
|
|
- return nil
|
|
|
+ return total, nil
|
|
|
}
|
|
|
-
|
|
|
+ total = searchResult.TotalHits()
|
|
|
if searchResult.Hits != nil {
|
|
|
resNum := len(searchResult.Hits.Hits)
|
|
|
if resNum < 5000 {
|
|
@@ -222,7 +224,7 @@ func get(index, itype, query, searchType string) *[]map[string]interface{} {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
- return &res
|
|
|
+ return total, &res
|
|
|
}
|
|
|
func GetOA(index, itype, query string) (*[]map[string]interface{}, int) {
|
|
|
//log.Println("query -- ", query)
|