瀏覽代碼

修改esv7

wangchuanjin 4 年之前
父節點
當前提交
8c129a0332
共有 1 個文件被更改,包括 7 次插入3 次删除
  1. 7 3
      esv7/elasticutil.go

+ 7 - 3
esv7/elasticutil.go

@@ -183,8 +183,8 @@ 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, query string) (int64, *[]map[string]interface{}) {
-	t, _, l := get(index, "", query, "dfs_query_then_fetch", true, true)
+func GetBySearchType(index, searchType, query string) (int64, *[]map[string]interface{}) {
+	t, _, l := get(index, "", searchType, query, true, true)
 	return t, l
 }
 func Get(index, itype, query string) *[]map[string]interface{} {
@@ -213,7 +213,11 @@ func get(index, itype, query, searchType string, isLimit, isHighlight bool) (int
 				}
 			}
 		}()
-		searchResult, err := client.Search().Index(index).Source(query).Do(context.TODO())
+		ss := client.Search().Index(index).Source(query)
+		if searchType != "" {
+			ss.SearchType(searchType)
+		}
+		searchResult, err := ss.Do(context.TODO())
 		if err != nil {
 			log.Println("从ES查询出错", err.Error())
 			return total, resNum, nil