forked from aquasecurity/esquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_boolean_test.go
107 lines (105 loc) · 2.21 KB
/
query_boolean_test.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
package query
import (
"testing"
)
func TestBool(t *testing.T) {
runMapTests(t, []mapTest{
{
"bool with only a simple must",
Bool().Must(Term("tag", "tech")),
map[string]interface{}{
"bool": map[string]interface{}{
"must": []map[string]interface{}{
{
"term": map[string]interface{}{
"tag": map[string]interface{}{
"value": "tech",
},
},
},
},
},
},
},
{
"bool which must match_all and filter",
Bool().Must(MatchAll()).Filter(Term("status", "active")),
map[string]interface{}{
"bool": map[string]interface{}{
"must": []map[string]interface{}{
{"match_all": map[string]interface{}{}},
},
"filter": []map[string]interface{}{
{
"term": map[string]interface{}{
"status": map[string]interface{}{
"value": "active",
},
},
},
},
},
},
},
{
"bool with a lot of stuff",
Bool().
Must(Term("user", "kimchy")).
Filter(Term("tag", "tech")).
MustNot(Range("age").Gte(10).Lte(20)).
Should(Term("tag", "wow"), Term("tag", "elasticsearch")).
MinimumShouldMatch(1).
Boost(1.1),
map[string]interface{}{
"bool": map[string]interface{}{
"must": []map[string]interface{}{
{
"term": map[string]interface{}{
"user": map[string]interface{}{
"value": "kimchy",
},
},
},
},
"filter": []map[string]interface{}{
{
"term": map[string]interface{}{
"tag": map[string]interface{}{
"value": "tech",
},
},
},
},
"must_not": []map[string]interface{}{
{
"range": map[string]interface{}{
"age": map[string]interface{}{
"gte": 10,
"lte": 20,
},
},
},
},
"should": []map[string]interface{}{
{
"term": map[string]interface{}{
"tag": map[string]interface{}{
"value": "wow",
},
},
},
{
"term": map[string]interface{}{
"tag": map[string]interface{}{
"value": "elasticsearch",
},
},
},
},
"minimum_should_match": 1,
"boost": 1.1,
},
},
},
})
}