forked from defensestation/osquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_match_all.go
53 lines (44 loc) · 1.29 KB
/
query_match_all.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
// 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"
// MatchAllQuery represents a query of type "match_all" or "match_none", as
// described in
// https://opensearch.org/docs/latest/query-dsl/match-all/
type MatchAllQuery struct {
all bool
params matchAllParams
}
type matchAllParams struct {
Boost float32 `structs:"boost,omitempty"`
}
// Map returns a map representation of the query, thus implementing the
// Mappable interface.
func (q *MatchAllQuery) Map() map[string]interface{} {
var mType string
switch q.all {
case true:
mType = "match_all"
default:
mType = "match_none"
}
return map[string]interface{}{
mType: structs.Map(q.params),
}
}
// MatchAll creates a new query of type "match_all".
func MatchAll() *MatchAllQuery {
return &MatchAllQuery{all: true}
}
// Boost assigns a score boost for documents matching the query.
func (q *MatchAllQuery) Boost(b float32) *MatchAllQuery {
if q.all {
q.params.Boost = b
}
return q
}
// MatchNone creates a new query of type "match_none".
func MatchNone() *MatchAllQuery {
return &MatchAllQuery{all: false}
}