xuzhiheng 2 vuotta sitten
vanhempi
commit
753eb178d1
2 muutettua tiedostoa jossa 34 lisäystä ja 9 poistoa
  1. 1 1
      src/service/second_push.go
  2. 33 8
      src/util/utiltag.go

+ 1 - 1
src/service/second_push.go

@@ -324,7 +324,7 @@ func searchProjectId(l map[string]interface{}, updateMap [][]map[string]interfac
 	return updateMap
 }
 func getProjectId(id string) string {
-	query := `{"query": {"bool": {"must": [{"term": {"projectset.ids": "%s"}}],"must_not": [],"should": []}}}`
+	query := `{"query": {"bool": {"must": [{"term": {"ids": "%s"}}],"must_not": [],"should": []}}}`
 	querys := fmt.Sprintf(query, id)
 	projectId := ""
 	projectIdArr := []string{}

+ 33 - 8
src/util/utiltag.go

@@ -71,6 +71,16 @@ func UtilEsSaveData(sdataid string, datas *[]map[string]interface{}) error {
 	return nil
 }
 
+type MySource struct {
+	Querys string
+}
+
+func (m *MySource) Source() (interface{}, error) {
+	mp := make(map[string]interface{})
+	json.Unmarshal([]byte(m.Querys), &mp)
+	return mp["query"], nil
+}
+
 // 客户规则
 func UtilEsFind1(tags map[string]interface{}) (error, int64) {
 	defer util.Catch()
@@ -111,15 +121,18 @@ func UtilEsFind1(tags map[string]interface{}) (error, int64) {
 	} else {
 		return errors.New("o_rules no found"), 0
 	}
-	ctx, _ := context.WithTimeout(context.Background(), 30*time.Second)
+	ctx, _ := context.WithTimeout(context.Background(), 5*time.Minute)
 	esCon := esv.VarEs.(*esv.EsV7)
 	client := esCon.GetEsConn()
 	defer esCon.DestoryEsConn(client)
-	esquery = esquery[:len(esquery)-1] + `,"size":` + fmt.Sprintf("%d", i_maxnum) + `}`
-	searchResult, err := client.Search(EsIndex).Source(esquery).Do(ctx)
+	// esquery = esquery[:len(esquery)-1] + `,"size":` + fmt.Sprintf("%d", i_maxnum) + `}`
+	cc := &MySource{
+		Querys: esquery,
+	}
+	searchResult, err := client.Search(EsIndex).Query(cc).Size(int(i_maxnum)).Do(ctx)
 	if err == nil && searchResult.Hits != nil {
 		datas := make([]map[string]interface{}, 0)
-		util.Debug("es查询到的数量:", searchResult.Hits.TotalHits)
+		util.Debug("es查询到的数量:", searchResult.Hits.TotalHits.Value)
 		util.Debug("es查询到的数量(实际):", len(searchResult.Hits.Hits))
 		for _, v := range searchResult.Hits.Hits {
 			wg.Add(1)
@@ -264,11 +277,11 @@ func UtilEsFind1(tags map[string]interface{}) (error, int64) {
 			}(v)
 		}
 		wg.Wait()
+		count := Es.Count(EsIndex, EsType, esquery)
 		Mgo.Update("entniche_rule", bson.M{"_id": tags["_id"]}, bson.M{
 			"$set": bson.M{
-				"i_estotal": searchResult.Hits.TotalHits.Value,
+				"i_estotal": count,
 			}}, false, false)
-		count := searchResult.Hits.TotalHits.Value
 		return UtilEsSaveData(sdataid, &datas), count
 	} else {
 		util.Debug(err)
@@ -569,7 +582,19 @@ func Utiltags(tag map[string]interface{}) string {
 		QueryObjecct.Bool = &ffBoolObject
 	}
 	if len(fqBoolObject.Must) > 0 || len(fqBoolObject.MustNot) > 0 || len(fqBoolObject.Should) > 0 {
-		QueryObjecct.Bool.Must = append(QueryObjecct.Bool.Must, &fqBoolObject)
+		if QueryObjecct.Bool == nil {
+			QueryObjecct.Bool = &fqBoolObject
+		} else {
+			if fqBoolObject.Must != nil {
+				QueryObjecct.Bool.Must = append(QueryObjecct.Bool.Must, fqBoolObject.Must...)
+			}
+			if fqBoolObject.Should != nil {
+				QueryObjecct.Bool.Should = append(QueryObjecct.Bool.Should, fqBoolObject.Should...)
+			}
+			if fqBoolObject.MustNot != nil {
+				QueryObjecct.Bool.MustNot = append(QueryObjecct.Bool.MustNot, fqBoolObject.MustNot...)
+			}
+		}
 		if len(torules.Should) > 0 {
 			QueryObjecct.Bool.Must = append(QueryObjecct.Bool.Must, map[string]interface{}{
 				"bool": torules,
@@ -924,7 +949,7 @@ func KeyWordToData(types, item, key string, keyWord []string) []string {
 }
 
 func GetProjectId(id string) string {
-	query := `{"query": {"bool": {"must": [{"term": {"projectset.ids": "%s"}}],"must_not": [],"should": []}}}`
+	query := `{"query": {"bool": {"must": [{"term": {"ids": "%s"}}],"must_not": [],"should": []}}}`
 	querys := fmt.Sprintf(query, id)
 	projectId := ""
 	projectIdArr := []string{}