-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
55_create_elastic_index_eventlogs.go
114 lines (108 loc) · 2.71 KB
/
55_create_elastic_index_eventlogs.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
108
109
110
111
112
113
114
package migrations
import (
"context"
"github.com/Seklfreak/Robyul2/cache"
)
func m55_create_elastic_index_eventlogs() {
if !cache.HasElastic() {
return
}
elastic := cache.GetElastic()
exists, err := elastic.IndexExists("robyul-eventlogs").Do(context.Background())
if err != nil {
panic(err)
}
if exists {
return
}
messageMapping := map[string]interface{}{
"mappings": map[string]interface{}{
"doc": map[string]interface{}{
"properties": map[string]interface{}{
"CreatedAt": map[string]interface{}{
"type": "date",
},
"GuildID": map[string]interface{}{
"type": "text",
"fields": map[string]interface{}{
"keyword": map[string]interface{}{
"type": "keyword",
},
},
},
"TargetID": map[string]interface{}{
"type": "text",
"fields": map[string]interface{}{
"keyword": map[string]interface{}{
"type": "keyword",
},
},
},
"TargetType": map[string]interface{}{
"type": "text",
},
"UserID": map[string]interface{}{
"type": "text",
"fields": map[string]interface{}{
"keyword": map[string]interface{}{
"type": "keyword",
},
},
},
"ActionType": map[string]interface{}{
"type": "text",
"fields": map[string]interface{}{
"keyword": map[string]interface{}{
"type": "keyword",
},
},
},
"Reason": map[string]interface{}{
"type": "text",
},
"Changes": map[string]interface{}{
"type": "nested",
"properties": map[string]interface{}{
"Key": map[string]interface{}{"type": "text"},
"OldValue": map[string]interface{}{"type": "text"},
"NewValue": map[string]interface{}{"type": "text"},
},
},
"Options": map[string]interface{}{
"type": "nested",
"properties": map[string]interface{}{
"Key": map[string]interface{}{
"type": "text",
},
"Value": map[string]interface{}{
"type": "text",
},
},
},
"WaitingFor": map[string]interface{}{
"properties": map[string]interface{}{
"AuditLogBackfill": map[string]interface{}{
"type": "boolean",
"null_value": false,
},
},
},
"Reverted": map[string]interface{}{
"type": "boolean",
"null_value": false,
},
"EventlogMessages": map[string]interface{}{
"type": "text",
},
},
},
},
}
index, err := elastic.CreateIndex("robyul-eventlogs").BodyJson(messageMapping).Do(context.Background())
if err != nil {
panic(err)
}
if !index.Acknowledged {
cache.GetLogger().WithField("module", "migrations").Error("ElasticSearch index not acknowledged")
}
}