use filter instead of must
Signed-off-by: huanggze <loganhuang@yunify.com>
This commit is contained in:
@@ -89,14 +89,12 @@ type BoolQuery struct {
|
|||||||
Bool interface{} `json:"bool"`
|
Bool interface{} `json:"bool"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FilterContext struct {
|
// user filter instead of must
|
||||||
|
// filter ignores scoring
|
||||||
|
type BoolFilter struct {
|
||||||
Filter []interface{} `json:"filter"`
|
Filter []interface{} `json:"filter"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BoolMust struct {
|
|
||||||
Must []interface{} `json:"must"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type BoolShould struct {
|
type BoolShould struct {
|
||||||
Should []interface{} `json:"should"`
|
Should []interface{} `json:"should"`
|
||||||
MinimumShouldMatch int64 `json:"minimum_should_match"`
|
MinimumShouldMatch int64 `json:"minimum_should_match"`
|
||||||
@@ -175,23 +173,23 @@ type DateHistogram struct {
|
|||||||
|
|
||||||
func createQueryRequest(param QueryParameters) (int, []byte, error) {
|
func createQueryRequest(param QueryParameters) (int, []byte, error) {
|
||||||
var request Request
|
var request Request
|
||||||
var mainBoolQuery FilterContext
|
var mainBoolQuery BoolFilter
|
||||||
|
|
||||||
if len(param.NamespaceWithCreationTime) != 0 {
|
if len(param.NamespaceWithCreationTime) != 0 {
|
||||||
var boolShoulds BoolShould
|
var boolShould BoolShould
|
||||||
for namespace, creationTime := range param.NamespaceWithCreationTime {
|
for namespace, creationTime := range param.NamespaceWithCreationTime {
|
||||||
var boolMusts BoolMust
|
var boolFilter BoolFilter
|
||||||
|
|
||||||
matchPhrase := MatchPhrase{MatchPhrase: map[string]string{fieldNamespaceNameKeyword: namespace}}
|
matchPhrase := MatchPhrase{MatchPhrase: map[string]string{fieldNamespaceNameKeyword: namespace}}
|
||||||
rangeQuery := RangeQuery{RangeSpec{TimeRange{creationTime, ""}}}
|
rangeQuery := RangeQuery{RangeSpec{TimeRange{creationTime, ""}}}
|
||||||
|
|
||||||
boolMusts.Must = append(boolMusts.Must, matchPhrase)
|
boolFilter.Filter = append(boolFilter.Filter, matchPhrase)
|
||||||
boolMusts.Must = append(boolMusts.Must, rangeQuery)
|
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
|
boolShould.MinimumShouldMatch = 1
|
||||||
mainBoolQuery.Filter = append(mainBoolQuery.Filter, BoolQuery{Bool: boolShoulds})
|
mainBoolQuery.Filter = append(mainBoolQuery.Filter, BoolQuery{Bool: boolShould})
|
||||||
}
|
}
|
||||||
if param.WorkloadFilter != nil {
|
if param.WorkloadFilter != nil {
|
||||||
boolQuery := makeBoolShould(matchPhrase, fieldPodNameKeyword, param.WorkloadFilter)
|
boolQuery := makeBoolShould(matchPhrase, fieldPodNameKeyword, param.WorkloadFilter)
|
||||||
|
|||||||
Reference in New Issue
Block a user