|
@@ -146,7 +146,7 @@ func Save(index, itype string, obj interface{}) bool {
|
|
|
//{"query":{"match_all":{}},"from":10,"size":10,"_source":["account_number","balance"],"sort":{"balance":{"order":"desc"}}}
|
|
|
//{"query":{"match_phrase":{"address":"milllane"}}}和match不同会去匹配整个短语,相当于must[]
|
|
|
func Get(index, itype, query string) *[]map[string]interface{} {
|
|
|
- //log.Println("query -- ", query)
|
|
|
+ log.Println("query -- ", query)
|
|
|
client := GetEsConn()
|
|
|
defer DestoryEsConn(client)
|
|
|
var res []map[string]interface{}
|
|
@@ -188,6 +188,41 @@ func Get(index, itype, query string) *[]map[string]interface{} {
|
|
|
return &res
|
|
|
}
|
|
|
|
|
|
+func GetNoLimit(index, itype, query string) *[]map[string]interface{} {
|
|
|
+ log.Println("query -- ", query)
|
|
|
+ client := GetEsConn()
|
|
|
+ defer DestoryEsConn(client)
|
|
|
+ var res []map[string]interface{}
|
|
|
+ if client != nil {
|
|
|
+ defer func() {
|
|
|
+ if r := recover(); r != nil {
|
|
|
+ log.Println("[E]", r)
|
|
|
+ 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 err != nil {
|
|
|
+ log.Println("从ES查询出错", err.Error())
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ if searchResult.Hits != nil {
|
|
|
+ resNum := len(searchResult.Hits.Hits)
|
|
|
+ res = make([]map[string]interface{}, resNum)
|
|
|
+ for i, hit := range searchResult.Hits.Hits {
|
|
|
+ json.Unmarshal(*hit.Source, &res[i])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return &res
|
|
|
+}
|
|
|
+
|
|
|
//分页查询
|
|
|
//{"name":"张三","$and":[{"age":{"$gt":10}},{"age":{"$lte":20}}]}
|
|
|
//fields直接是 `"_id","title"`
|
|
@@ -767,9 +802,7 @@ func Count(index, itype string, query interface{}) int64 {
|
|
|
if err != nil {
|
|
|
log.Println("统计出错", err.Error())
|
|
|
}
|
|
|
- if n > 500 {
|
|
|
- n = 500
|
|
|
- }
|
|
|
+
|
|
|
return n
|
|
|
}
|
|
|
return 0
|