-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathquery_constant_score.go
More file actions
49 lines (42 loc) · 1.5 KB
/
query_constant_score.go
File metadata and controls
49 lines (42 loc) · 1.5 KB
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
// Modified by DefenseStation on 2024-06-06
// Changes: Updated ElasticSearch client to OpenSearch client, changed package name to 'osquery',
// updated references to OpenSearch documentation, and modified examples accordingly.
package osquery
import "github.com/fatih/structs"
// ConstantScoreQuery represents a compound query of type "constant_score", as
// described in
// https://opensearch.org/docs/latest/query-dsl/compound/constant-score/
type ConstantScoreQuery struct {
filter Mappable
boost float32
name string
}
// ConstantScore creates a new query of type "constant_score" with the provided
// filter query.
func ConstantScore(filter Mappable) *ConstantScoreQuery {
return &ConstantScoreQuery{
filter: filter,
}
}
// Boost sets the boost value of the query.
func (q *ConstantScoreQuery) Boost(b float32) *ConstantScoreQuery {
q.boost = b
return q
}
// Name sets the name of the query that is returned in matched_queries in response
// if document matches the query.
func (q *ConstantScoreQuery) Name(name string) *ConstantScoreQuery {
q.name = name
return q
}
// Map returns a map representation of the query, thus implementing the
// Mappable interface.
func (q *ConstantScoreQuery) Map() map[string]interface{} {
return map[string]interface{}{
"constant_score": structs.Map(struct {
Filter map[string]interface{} `structs:"filter"`
Boost float32 `structs:"boost,omitempty"`
Name string `structs:"_name,omitempty"`
}{q.filter.Map(), q.boost, q.name}),
}
}