forked from defensestation/osquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_script_score_test.go
70 lines (67 loc) · 1.88 KB
/
query_script_score_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
// Modified by Sushmita on 2025-01-31
// Changes: Updated ElasticSearch client to OpenSearch client, changed package name to 'osquery',
// updated references to OpenSearch documentation, and modified examples accordingly.
package osquery
import (
"testing"
)
func TestScriptScore(t *testing.T) {
runMapTests(t, []mapTest{
{
"script_score query without boost or min_score",
ScriptScore(Term("user", "kimchy"), Script("my_script").Source("doc['field_name'].value * _score")),
map[string]interface{}{
"script_score": map[string]interface{}{
"query": map[string]interface{}{
"term": map[string]interface{}{
"user": map[string]interface{}{
"value": "kimchy",
},
},
},
"script": map[string]interface{}{
"source": "doc['field_name'].value * _score",
},
},
},
},
{
"script_score query with boost",
ScriptScore(Term("user", "kimchy"), Script("my_script").Source("doc['field_name'].value * _score")).Boost(1.0),
map[string]interface{}{
"script_score": map[string]interface{}{
"query": map[string]interface{}{
"term": map[string]interface{}{
"user": map[string]interface{}{
"value": "kimchy",
},
},
},
"script": map[string]interface{}{
"source": "doc['field_name'].value * _score",
},
"boost": 1.0,
},
},
},
{
"script_score query with min_score",
ScriptScore(Term("user", "kimchy"), Script("my_script").Source("doc['field_name'].value * _score")).MinScore(2.2),
map[string]interface{}{
"script_score": map[string]interface{}{
"query": map[string]interface{}{
"term": map[string]interface{}{
"user": map[string]interface{}{
"value": "kimchy",
},
},
},
"script": map[string]interface{}{
"source": "doc['field_name'].value * _score",
},
"min_score": 2.2,
},
},
},
})
}