/
range_field.go
135 lines (120 loc) · 4.19 KB
/
range_field.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package mapping
// A RangeField type represent a continuous range of values between an upper and
// lower bound. For example, a range can represent any date in October or any
// integer from 0 to 9. They are defined using the operators gt or gte for the
// lower bound, and lt or lte for the upper bound. They can be used for
// querying, and have limited support for aggregations. The only supported
// aggregations are histogram, cardinality.
//
// https://www.elastic.co/guide/en/elasticsearch/reference/current/range.html
// IntegerRangeField is a range of signed 32-bit integers with a minimum value
// of -231 and maximum of 231-1.
type IntegerRangeField struct {
BaseField `bson:",inline" json:",inline"`
CoerceParam `bson:",inline" json:",inline"`
IndexParam `bson:",inline" json:",inline"`
StoreParam `bson:",inline" json:",inline"`
}
func (f IntegerRangeField) Clone() Field {
n := NewIntegerRangeField()
n.SetCoerce(f.Coerce())
n.SetIndex(f.Index())
n.SetStore(f.Store())
return n
}
func NewIntegerRangeField() *IntegerRangeField {
return &IntegerRangeField{BaseField: BaseField{MappingType: TypeIntegerRange}}
}
// FloatRangeField is a range of single-precision 32-bit IEEE 754 floating point
// values.
type FloatRangeField struct {
BaseField `bson:",inline" json:",inline"`
CoerceParam `bson:",inline" json:",inline"`
IndexParam `bson:",inline" json:",inline"`
StoreParam `bson:",inline" json:",inline"`
}
func (f FloatRangeField) Clone() Field {
n := NewFloatRangeField()
n.SetCoerce(f.Coerce())
n.SetIndex(f.Index())
n.SetStore(f.Store())
return n
}
func NewFloatRangeField() *FloatRangeField {
return &FloatRangeField{BaseField: BaseField{MappingType: TypeFloatRange}}
}
// LongRangeField is a range of signed 64-bit integers with a minimum value of
// -263 and maximum of 263-1.
type LongRangeField struct {
BaseField `bson:",inline" json:",inline"`
CoerceParam `bson:",inline" json:",inline"`
IndexParam `bson:",inline" json:",inline"`
StoreParam `bson:",inline" json:",inline"`
}
func (f LongRangeField) Clone() Field {
n := NewLongRangeField()
n.SetCoerce(f.Coerce())
n.SetIndex(f.Index())
n.SetStore(f.Store())
return n
}
func NewLongRangeField() *LongRangeField {
return &LongRangeField{BaseField: BaseField{MappingType: TypeLongRange}}
}
// DoubleRangeField is a range of double-precision 64-bit IEEE 754 floating
// point values.
type DoubleRangeField struct {
BaseField `bson:",inline" json:",inline"`
CoerceParam `bson:",inline" json:",inline"`
IndexParam `bson:",inline" json:",inline"`
StoreParam `bson:",inline" json:",inline"`
}
func (f DoubleRangeField) Clone() Field {
n := NewDoubleRangeField()
n.SetCoerce(f.Coerce())
n.SetIndex(f.Index())
n.SetStore(f.Store())
return n
}
func NewDoubleRangeField() *DoubleRangeField {
return &DoubleRangeField{BaseField: BaseField{MappingType: TypeDoubleRange}}
}
// DateRangeField is a range of date values. Date ranges support various date
// formats through the format mapping parameter. Regardless of the format used,
// date values are parsed into an unsigned 64-bit integer representing
// milliseconds since the Unix epoch in UTC. Values containing the now date math
// expression are not supported.
type DateRangeField struct {
BaseField `bson:",inline" json:",inline"`
CoerceParam `bson:",inline" json:",inline"`
IndexParam `bson:",inline" json:",inline"`
StoreParam `bson:",inline" json:",inline"`
}
func (f DateRangeField) Clone() Field {
n := NewDateRangeField()
n.SetCoerce(f.Coerce())
n.SetIndex(f.Index())
n.SetStore(f.Store())
return n
}
func NewDateRangeField() *DateRangeField {
return &DateRangeField{BaseField: BaseField{MappingType: TypeDateRange}}
}
// IPRangeField is a range of ip values supporting either IPv4 or IPv6 (or
// mixed) addresses.
type IPRangeField struct {
BaseField `bson:",inline" json:",inline"`
CoerceParam `bson:",inline" json:",inline"`
IndexParam `bson:",inline" json:",inline"`
StoreParam `bson:",inline" json:",inline"`
}
func (f IPRangeField) Clone() Field {
n := NewIPRangeField()
n.SetCoerce(f.Coerce())
n.SetIndex(f.Index())
n.SetStore(f.Store())
return n
}
func NewIPRangeField() *IPRangeField {
return &IPRangeField{BaseField: BaseField{MappingType: TypeIPRange}}
}