-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
45_create_elastic_index_messages.go
77 lines (71 loc) · 1.67 KB
/
45_create_elastic_index_messages.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
package migrations
import (
"context"
"github.com/Seklfreak/Robyul2/cache"
)
func m45_create_elastic_index_messages() {
if !cache.HasElastic() {
return
}
elastic := cache.GetElastic()
exists, err := elastic.IndexExists("robyul-messages-v2").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",
},
"MessageID": map[string]interface{}{
"type": "text",
"fields": map[string]interface{}{
"keyword": map[string]interface{}{
"type": "keyword",
},
},
},
"Content": map[string]interface{}{
"type": "text",
"index": false,
},
"ContentLength": map[string]interface{}{
"type": "long",
},
"Attachments": map[string]interface{}{
"type": "text",
},
"UserID": map[string]interface{}{
"type": "text",
"fields": map[string]interface{}{
"keyword": map[string]interface{}{
"type": "keyword",
},
},
},
"GuildID": map[string]interface{}{
"type": "text",
},
"ChannelID": map[string]interface{}{
"type": "text",
},
"Embeds": map[string]interface{}{
"type": "integer",
},
},
},
},
}
index, err := elastic.CreateIndex("robyul-messages-v2").BodyJson(messageMapping).Do(context.Background())
if err != nil {
panic(err)
}
if !index.Acknowledged {
cache.GetLogger().WithField("module", "migrations").Error("ElasticSearch index not acknowledged")
}
}