From 1badf13538276e4db0c02c518a42049b9c68f51f Mon Sep 17 00:00:00 2001 From: huanggze Date: Wed, 4 Sep 2019 14:17:15 +0800 Subject: [PATCH] use filter instead of must Signed-off-by: huanggze --- pkg/simple/client/elasticsearch/esclient.go | 24 ++++++++++----------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/pkg/simple/client/elasticsearch/esclient.go b/pkg/simple/client/elasticsearch/esclient.go index 4211fc6c0..745ff5f25 100644 --- a/pkg/simple/client/elasticsearch/esclient.go +++ b/pkg/simple/client/elasticsearch/esclient.go @@ -89,14 +89,12 @@ type BoolQuery struct { Bool interface{} `json:"bool"` } -type FilterContext struct { +// user filter instead of must +// filter ignores scoring +type BoolFilter struct { Filter []interface{} `json:"filter"` } -type BoolMust struct { - Must []interface{} `json:"must"` -} - type BoolShould struct { Should []interface{} `json:"should"` MinimumShouldMatch int64 `json:"minimum_should_match"` @@ -175,23 +173,23 @@ type DateHistogram struct { func createQueryRequest(param QueryParameters) (int, []byte, error) { var request Request - var mainBoolQuery FilterContext + var mainBoolQuery BoolFilter if len(param.NamespaceWithCreationTime) != 0 { - var boolShoulds BoolShould + var boolShould BoolShould for namespace, creationTime := range param.NamespaceWithCreationTime { - var boolMusts BoolMust + var boolFilter BoolFilter matchPhrase := MatchPhrase{MatchPhrase: map[string]string{fieldNamespaceNameKeyword: namespace}} rangeQuery := RangeQuery{RangeSpec{TimeRange{creationTime, ""}}} - boolMusts.Must = append(boolMusts.Must, matchPhrase) - boolMusts.Must = append(boolMusts.Must, rangeQuery) + boolFilter.Filter = append(boolFilter.Filter, matchPhrase) + boolFilter.Filter = append(boolFilter.Filter, rangeQuery) - boolShoulds.Should = append(boolShoulds.Should, BoolQuery{Bool: boolMusts}) + boolShould.Should = append(boolShould.Should, BoolQuery{Bool: boolFilter}) } - boolShoulds.MinimumShouldMatch = 1 - mainBoolQuery.Filter = append(mainBoolQuery.Filter, BoolQuery{Bool: boolShoulds}) + boolShould.MinimumShouldMatch = 1 + mainBoolQuery.Filter = append(mainBoolQuery.Filter, BoolQuery{Bool: boolShould}) } if param.WorkloadFilter != nil { boolQuery := makeBoolShould(matchPhrase, fieldPodNameKeyword, param.WorkloadFilter)