@@ -9,80 +9,60 @@ package elastic
99// For details, see
1010// https://www.elastic.co/guide/en/elasticsearch/reference/7.0/query-dsl-range-query.html
1111type 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
2222}
2323
2424// NewRangeQuery creates and initializes a new RangeQuery.
2525func NewRangeQuery (name string ) * RangeQuery {
26- return & RangeQuery {name : name , includeLower : true , includeUpper : true }
26+ return & RangeQuery {name : name }
2727}
2828
2929// From indicates the from part of the RangeQuery.
3030// Use nil to indicate an unbounded from part.
3131func (q * RangeQuery ) From (from interface {}) * RangeQuery {
32- q .from = from
33- return q
32+ return q .Gte (from )
3433}
3534
3635// Gt indicates a greater-than value for the from part.
3736// Use nil to indicate an unbounded from part.
3837func (q * RangeQuery ) Gt (from interface {}) * RangeQuery {
39- q .from = from
40- q .includeLower = false
38+ q .gt = from
4139 return q
4240}
4341
4442// Gte indicates a greater-than-or-equal value for the from part.
4543// Use nil to indicate an unbounded from part.
4644func (q * RangeQuery ) Gte (from interface {}) * RangeQuery {
47- q .from = from
48- q .includeLower = true
45+ q .gte = from
4946 return q
5047}
5148
5249// To indicates the to part of the RangeQuery.
5350// Use nil to indicate an unbounded to part.
5451func (q * RangeQuery ) To (to interface {}) * RangeQuery {
55- q .to = to
56- return q
52+ return q .Lte (to )
5753}
5854
5955// Lt indicates a less-than value for the to part.
6056// Use nil to indicate an unbounded to part.
6157func (q * RangeQuery ) Lt (to interface {}) * RangeQuery {
62- q .to = to
63- q .includeUpper = false
58+ q .lt = to
6459 return q
6560}
6661
6762// Lte indicates a less-than-or-equal value for the to part.
6863// Use nil to indicate an unbounded to part.
6964func (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
8666 return q
8767}
8868
@@ -130,8 +110,22 @@ func (q *RangeQuery) Source() (interface{}, error) {
130110 params := make (map [string ]interface {})
131111 rangeQ [q .name ] = params
132112
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+
135129 if q .timeZone != "" {
136130 params ["time_zone" ] = q .timeZone
137131 }
@@ -144,8 +138,6 @@ func (q *RangeQuery) Source() (interface{}, error) {
144138 if q .boost != nil {
145139 params ["boost" ] = * q .boost
146140 }
147- params ["include_lower" ] = q .includeLower
148- params ["include_upper" ] = q .includeUpper
149141
150142 if q .queryName != "" {
151143 rangeQ ["_name" ] = q .queryName
0 commit comments