未验证 提交 1badf135 编写于 作者: H huanggze

use filter instead of must

Signed-off-by: Nhuanggze <loganhuang@yunify.com>
上级 78e8227f
...@@ -89,14 +89,12 @@ type BoolQuery struct { ...@@ -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 { ...@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册