-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
51_reindex_elasticv5_to_v6.go
87 lines (75 loc) · 3.08 KB
/
51_reindex_elasticv5_to_v6.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
package migrations
import (
"context"
"github.com/Seklfreak/Robyul2/cache"
"github.com/olivere/elastic"
)
func m51_reindex_elasticv5_to_v6() {
if !cache.HasElastic() {
return
}
elasticClient := cache.GetElastic()
exists, err := elasticClient.IndexExists("robyul").Do(context.Background())
if err != nil {
panic(err)
}
if !exists {
return
}
cache.GetLogger().WithField("module", "migrations").Info("reindexing ElasticSearch indexes")
src := elastic.NewReindexSource().Index("robyul").Type("message")
dst := elastic.NewReindexDestination().Index("robyul-messages-v2").Type("doc")
res, err := elasticClient.Reindex().Source(src).Destination(dst).Refresh("true").Do(context.Background())
if err != nil {
panic(err)
}
cache.GetLogger().WithField("module", "migrations").Infof(
"Reindexed a total of %d message documents", res.Total)
src = elastic.NewReindexSource().Index("robyul").Type("join")
dst = elastic.NewReindexDestination().Index("robyul-joins").Type("doc")
res, err = elasticClient.Reindex().Source(src).Destination(dst).Refresh("true").Do(context.Background())
if err != nil {
panic(err)
}
cache.GetLogger().WithField("module", "migrations").Infof(
"Reindexed a total of %d join documents", res.Total)
src = elastic.NewReindexSource().Index("robyul").Type("leave")
dst = elastic.NewReindexDestination().Index("robyul-leaves").Type("doc")
res, err = elasticClient.Reindex().Source(src).Destination(dst).Refresh("true").Do(context.Background())
if err != nil {
panic(err)
}
cache.GetLogger().WithField("module", "migrations").Infof(
"Reindexed a total of %d leave documents", res.Total)
src = elastic.NewReindexSource().Index("robyul").Type("reaction")
dst = elastic.NewReindexDestination().Index("robyul-reactions").Type("doc")
res, err = elasticClient.Reindex().Source(src).Destination(dst).Refresh("true").Do(context.Background())
if err != nil {
panic(err)
}
cache.GetLogger().WithField("module", "migrations").Infof(
"Reindexed a total of %d reaction documents", res.Total)
src = elastic.NewReindexSource().Index("robyul").Type("presence_update")
dst = elastic.NewReindexDestination().Index("robyul-presence_updates").Type("doc")
res, err = elasticClient.Reindex().Source(src).Destination(dst).Refresh("true").Do(context.Background())
if err != nil {
panic(err)
}
cache.GetLogger().WithField("module", "migrations").Infof(
"Reindexed a total of %d presence update documents", res.Total)
src = elastic.NewReindexSource().Index("robyul").Type("vanity_invite_click")
dst = elastic.NewReindexDestination().Index("robyul-vanity_invite_clicks").Type("doc")
res, err = elasticClient.Reindex().Source(src).Destination(dst).Refresh("true").Do(context.Background())
if err != nil {
panic(err)
}
cache.GetLogger().WithField("module", "migrations").Infof(
"Reindexed a total of %d vanity invite click documents", res.Total)
index, err := elasticClient.DeleteIndex("robyul").Do(context.Background())
if err != nil {
panic(err)
}
if !index.Acknowledged {
cache.GetLogger().WithField("module", "migrations").Error("ElasticSearch index not acknowledged")
}
}