-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
search_facets_histogram.go
110 lines (93 loc) · 2.34 KB
/
search_facets_histogram.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
// 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
// Histogram Facet
// See: http://www.elasticsearch.org/guide/reference/api/search/facets/histogram-facet.html
type HistogramFacet struct {
facetFilter Filter
global *bool
nested string
mode string
keyField string
valueField string
interval int64
timeInterval string
comparatorType string
}
func NewHistogramFacet() HistogramFacet {
return HistogramFacet{
interval: -1,
}
}
func (f HistogramFacet) FacetFilter(filter Facet) HistogramFacet {
f.facetFilter = filter
return f
}
func (f HistogramFacet) Global(global bool) HistogramFacet {
f.global = &global
return f
}
func (f HistogramFacet) Nested(nested string) HistogramFacet {
f.nested = nested
return f
}
func (f HistogramFacet) Mode(mode string) HistogramFacet {
f.mode = mode
return f
}
func (f HistogramFacet) Field(field string) HistogramFacet {
f.keyField = field
return f
}
func (f HistogramFacet) KeyField(keyField string) HistogramFacet {
f.keyField = keyField
return f
}
func (f HistogramFacet) ValueField(valueField string) HistogramFacet {
f.valueField = valueField
return f
}
func (f HistogramFacet) Interval(interval int64) HistogramFacet {
f.interval = interval
return f
}
func (f HistogramFacet) TimeInterval(timeInterval string) HistogramFacet {
f.timeInterval = timeInterval
return f
}
func (f HistogramFacet) addFilterFacetAndGlobal(source map[string]interface{}) {
if f.facetFilter != nil {
source["facet_filter"] = f.facetFilter.Source()
}
if f.nested != "" {
source["nested"] = f.nested
}
if f.global != nil {
source["global"] = *f.global
}
if f.mode != "" {
source["mode"] = f.mode
}
}
func (f HistogramFacet) Source() interface{} {
source := make(map[string]interface{})
f.addFilterFacetAndGlobal(source)
opts := make(map[string]interface{})
source["histogram"] = opts
if f.valueField != "" {
opts["key_field"] = f.keyField
opts["value_field"] = f.valueField
} else {
opts["field"] = f.keyField
}
if f.timeInterval != "" {
opts["time_interval"] = f.timeInterval
} else {
opts["interval"] = f.interval
}
if f.comparatorType != "" {
opts["comparator"] = f.comparatorType
}
return source
}