1 Star 1 Fork 0

宇宙蒙面侠X/github.com-olivere-elastic

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
search_queries_range.go 2.70 KB
Copy Edit Raw Blame History
// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
// Use of this source code is governed by a MIT-license.
// See http://olivere.mit-license.org/license.txt for details.
package elastic
// Matches documents with fields that have terms within a certain range.
// For details, see:
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-range-query.html
type RangeQuery struct {
Query
name string
from *interface{}
to *interface{}
timeZone string
format string
includeLower bool
includeUpper bool
boost *float64
queryName string
}
func NewRangeQuery(name string) RangeQuery {
q := RangeQuery{name: name, includeLower: true, includeUpper: true}
return q
}
// TimeZone allows for adjusting the from/to fields using a time zone.
// Only valid for date fields.
func (q RangeQuery) TimeZone(timeZone string) RangeQuery {
q.timeZone = timeZone
return q
}
// Format is a valid option for date fields in a Range query.
func (q RangeQuery) Format(format string) RangeQuery {
q.format = format
return q
}
func (q RangeQuery) From(from interface{}) RangeQuery {
q.from = &from
return q
}
func (q RangeQuery) Gt(from interface{}) RangeQuery {
q.from = &from
q.includeLower = false
return q
}
func (q RangeQuery) Gte(from interface{}) RangeQuery {
q.from = &from
q.includeLower = true
return q
}
func (q RangeQuery) To(to interface{}) RangeQuery {
q.to = &to
return q
}
func (q RangeQuery) Lt(to interface{}) RangeQuery {
q.to = &to
q.includeUpper = false
return q
}
func (q RangeQuery) Lte(to interface{}) RangeQuery {
q.to = &to
q.includeUpper = true
return q
}
func (q RangeQuery) IncludeLower(includeLower bool) RangeQuery {
q.includeLower = includeLower
return q
}
func (q RangeQuery) IncludeUpper(includeUpper bool) RangeQuery {
q.includeUpper = includeUpper
return q
}
func (q RangeQuery) Boost(boost float64) RangeQuery {
q.boost = &boost
return q
}
func (q RangeQuery) QueryName(queryName string) RangeQuery {
q.queryName = queryName
return q
}
func (q RangeQuery) Source() interface{} {
// {
// "range" : {
// "name" : {
// "..." : "..."
// }
// }
// }
source := make(map[string]interface{})
rangeQ := make(map[string]interface{})
source["range"] = rangeQ
params := make(map[string]interface{})
rangeQ[q.name] = params
params["from"] = q.from
params["to"] = q.to
if q.timeZone != "" {
params["time_zone"] = q.timeZone
}
if q.format != "" {
params["format"] = q.format
}
params["include_lower"] = q.includeLower
params["include_upper"] = q.includeUpper
if q.boost != nil {
rangeQ["boost"] = *q.boost
}
if q.queryName != "" {
rangeQ["_name"] = q.queryName
}
return source
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/awol2010ex/github.com-olivere-elastic.git
git@gitee.com:awol2010ex/github.com-olivere-elastic.git
awol2010ex
github.com-olivere-elastic
github.com-olivere-elastic
v2.0.36

Search

0d507c66 1850385 C8b1a773 1850385