-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathsearch_queries_interval_rules_prefix.go
57 lines (47 loc) · 1.49 KB
/
search_queries_interval_rules_prefix.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
package elastic
var (
_ IntervalQueryRule = (*IntervalQueryRulePrefix)(nil)
)
// IntervalQueryRulePrefix is an implementation of IntervalQueryRule.
//
// See https://www.elastic.co/guide/en/elasticsearch/reference/7.5/query-dsl-intervals-query.html#intervals-prefix
// for details.
type IntervalQueryRulePrefix struct {
prefix string
analyzer string
useField string
}
// NewIntervalQueryRulePrefix initializes and returns a new instance
// of IntervalQueryRulePrefix.
func NewIntervalQueryRulePrefix(prefix string) *IntervalQueryRulePrefix {
return &IntervalQueryRulePrefix{prefix: prefix}
}
// Analyzer specifies the analyzer used to analyze terms in the query.
func (r *IntervalQueryRulePrefix) Analyzer(analyzer string) *IntervalQueryRulePrefix {
r.analyzer = analyzer
return r
}
// UseField, if specified, matches the intervals from this field rather than
// the top-level field.
func (r *IntervalQueryRulePrefix) UseField(useField string) *IntervalQueryRulePrefix {
r.useField = useField
return r
}
// Source returns JSON for the function score query.
func (r *IntervalQueryRulePrefix) Source() (interface{}, error) {
source := make(map[string]interface{})
source["query"] = r.prefix
if r.analyzer != "" {
source["analyzer"] = r.analyzer
}
if r.useField != "" {
source["use_field"] = r.useField
}
return map[string]interface{}{
"prefix": source,
}, nil
}
// isIntervalQueryRule implements the marker interface.
func (r *IntervalQueryRulePrefix) isIntervalQueryRule() bool {
return true
}