From aabf2584c28e0d33ad9ccc0b17e6d70ebe5c6e23 Mon Sep 17 00:00:00 2001 From: ryou zhang Date: Mon, 27 Jun 2022 20:40:29 +0800 Subject: [PATCH 1/2] use range query new dsl --- search_queries_range.go | 17 ++++++++++++----- search_queries_script_score.go | 2 +- xpack_security_get_role.go | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/search_queries_range.go b/search_queries_range.go index e3c07308b..8510430a0 100644 --- a/search_queries_range.go +++ b/search_queries_range.go @@ -29,7 +29,7 @@ func NewRangeQuery(name string) *RangeQuery { // From indicates the from part of the RangeQuery. // Use nil to indicate an unbounded from part. func (q *RangeQuery) From(from interface{}) *RangeQuery { - q.from = from + q.gt = from return q } @@ -130,8 +130,17 @@ func (q *RangeQuery) Source() (interface{}, error) { params := make(map[string]interface{}) rangeQ[q.name] = params - params["from"] = q.from - params["to"] = q.to + if q.includeLower { + params["gte"] = q.from + } else { + params["gt"] = q.from + } + + if q.includeUpper { + params["lte"] = q.to + } else { + params["lt"] = q.to + } if q.timeZone != "" { params["time_zone"] = q.timeZone } @@ -144,8 +153,6 @@ func (q *RangeQuery) Source() (interface{}, error) { if q.boost != nil { params["boost"] = *q.boost } - params["include_lower"] = q.includeLower - params["include_upper"] = q.includeUpper if q.queryName != "" { rangeQ["_name"] = q.queryName diff --git a/search_queries_script_score.go b/search_queries_script_score.go index 7f00e0fe3..42a794588 100644 --- a/search_queries_script_score.go +++ b/search_queries_script_score.go @@ -24,7 +24,7 @@ type ScriptScoreQuery struct { // NewScriptScoreQuery creates and initializes a new script_score query. func NewScriptScoreQuery(query Query, script *Script) *ScriptScoreQuery { return &ScriptScoreQuery{ - query: query, + query: query, script: script, } } diff --git a/xpack_security_get_role.go b/xpack_security_get_role.go index fbddf6b67..9f77431d3 100644 --- a/xpack_security_get_role.go +++ b/xpack_security_get_role.go @@ -174,7 +174,7 @@ type XPackSecurityRole struct { type XPackSecurityApplicationPrivileges struct { Application string `json:"application"` Privileges []string `json:"privileges"` - Resources []string `json:"resources"` + Resources []string `json:"resources"` } // XPackSecurityIndicesPermissions is the indices permission object From f33f72549261a26d656d835c98c53e9da49e2664 Mon Sep 17 00:00:00 2001 From: ryou zhang Date: Mon, 27 Jun 2022 20:41:33 +0800 Subject: [PATCH 2/2] fix bug --- search_queries_range.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/search_queries_range.go b/search_queries_range.go index 8510430a0..3ed0b811f 100644 --- a/search_queries_range.go +++ b/search_queries_range.go @@ -29,7 +29,7 @@ func NewRangeQuery(name string) *RangeQuery { // From indicates the from part of the RangeQuery. // Use nil to indicate an unbounded from part. func (q *RangeQuery) From(from interface{}) *RangeQuery { - q.gt = from + q.from = from return q }