Fetch the repository succeeded.
// 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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。