@@ -9,80 +9,60 @@ package elastic
9
9
// For details, see
10
10
// https://www.elastic.co/guide/en/elasticsearch/reference/7.0/query-dsl-range-query.html
11
11
type RangeQuery struct {
12
- name string
13
- from interface {}
14
- to interface {}
15
- timeZone string
16
- includeLower bool
17
- includeUpper bool
18
- boost * float64
19
- queryName string
20
- format string
21
- relation string
12
+ name string
13
+ gt interface {}
14
+ gte interface {}
15
+ lt interface {}
16
+ lte interface {}
17
+ timeZone string
18
+ boost * float64
19
+ queryName string
20
+ format string
21
+ relation string
22
22
}
23
23
24
24
// NewRangeQuery creates and initializes a new RangeQuery.
25
25
func NewRangeQuery (name string ) * RangeQuery {
26
- return & RangeQuery {name : name , includeLower : true , includeUpper : true }
26
+ return & RangeQuery {name : name }
27
27
}
28
28
29
29
// From indicates the from part of the RangeQuery.
30
30
// Use nil to indicate an unbounded from part.
31
31
func (q * RangeQuery ) From (from interface {}) * RangeQuery {
32
- q .from = from
33
- return q
32
+ return q .Gte (from )
34
33
}
35
34
36
35
// Gt indicates a greater-than value for the from part.
37
36
// Use nil to indicate an unbounded from part.
38
37
func (q * RangeQuery ) Gt (from interface {}) * RangeQuery {
39
- q .from = from
40
- q .includeLower = false
38
+ q .gt = from
41
39
return q
42
40
}
43
41
44
42
// Gte indicates a greater-than-or-equal value for the from part.
45
43
// Use nil to indicate an unbounded from part.
46
44
func (q * RangeQuery ) Gte (from interface {}) * RangeQuery {
47
- q .from = from
48
- q .includeLower = true
45
+ q .gte = from
49
46
return q
50
47
}
51
48
52
49
// To indicates the to part of the RangeQuery.
53
50
// Use nil to indicate an unbounded to part.
54
51
func (q * RangeQuery ) To (to interface {}) * RangeQuery {
55
- q .to = to
56
- return q
52
+ return q .Lte (to )
57
53
}
58
54
59
55
// Lt indicates a less-than value for the to part.
60
56
// Use nil to indicate an unbounded to part.
61
57
func (q * RangeQuery ) Lt (to interface {}) * RangeQuery {
62
- q .to = to
63
- q .includeUpper = false
58
+ q .lt = to
64
59
return q
65
60
}
66
61
67
62
// Lte indicates a less-than-or-equal value for the to part.
68
63
// Use nil to indicate an unbounded to part.
69
64
func (q * RangeQuery ) Lte (to interface {}) * RangeQuery {
70
- q .to = to
71
- q .includeUpper = true
72
- return q
73
- }
74
-
75
- // IncludeLower indicates whether the lower bound should be included or not.
76
- // Defaults to true.
77
- func (q * RangeQuery ) IncludeLower (includeLower bool ) * RangeQuery {
78
- q .includeLower = includeLower
79
- return q
80
- }
81
-
82
- // IncludeUpper indicates whether the upper bound should be included or not.
83
- // Defaults to true.
84
- func (q * RangeQuery ) IncludeUpper (includeUpper bool ) * RangeQuery {
85
- q .includeUpper = includeUpper
65
+ q .lte = to
86
66
return q
87
67
}
88
68
@@ -130,8 +110,22 @@ func (q *RangeQuery) Source() (interface{}, error) {
130
110
params := make (map [string ]interface {})
131
111
rangeQ [q .name ] = params
132
112
133
- params ["from" ] = q .from
134
- params ["to" ] = q .to
113
+ if nil != q .gt {
114
+ params ["gt" ] = q .gt
115
+ }
116
+
117
+ if nil != q .gte {
118
+ params ["gte" ] = q .gte
119
+ }
120
+
121
+ if nil != q .lt {
122
+ params ["lt" ] = q .lt
123
+ }
124
+
125
+ if nil != q .lte {
126
+ params ["lte" ] = q .lte
127
+ }
128
+
135
129
if q .timeZone != "" {
136
130
params ["time_zone" ] = q .timeZone
137
131
}
@@ -144,8 +138,6 @@ func (q *RangeQuery) Source() (interface{}, error) {
144
138
if q .boost != nil {
145
139
params ["boost" ] = * q .boost
146
140
}
147
- params ["include_lower" ] = q .includeLower
148
- params ["include_upper" ] = q .includeUpper
149
141
150
142
if q .queryName != "" {
151
143
rangeQ ["_name" ] = q .queryName
0 commit comments