forked from utmstack/UTMStack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.go
69 lines (60 loc) · 1.46 KB
/
search.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
package main
import (
"time"
"github.com/levigross/grequests"
)
func InitOpenSearch() error {
baseURL := "http://127.0.0.1:9200/"
for intent := 0; intent <= 10; intent++ {
time.Sleep(1 * time.Minute)
_, err := grequests.Get(baseURL+"_cluster/healt", &grequests.RequestOptions{
Params: map[string]string{
"wait_for_status": "green",
"timeout": "50s",
},
})
if err != nil {
if intent >= 10 {
return err
}
} else {
break
}
}
_, err := grequests.Put(baseURL+"_snapshot/.utm_geoip", &grequests.RequestOptions{
JSON: map[string]interface{}{
"type": "fs",
"settings": map[string]interface{}{
"location": "/usr/share/opensearch/.utm-geoip/",
"readonly": true,
},
},
})
if err != nil {
return err
}
_, err = grequests.Put(baseURL+"_index_template/utmstack_indexes", &grequests.RequestOptions{
JSON: map[string]interface{}{
"index_patterns": []string{"alert-*", "log-*", ".utm-*", ".utmstack-*"},
"template": map[string]interface{}{
"settings": map[string]interface{}{
"index.number_of_shards": 1,
"index.number_of_replicas": 0,
"index.mapping.total_fields.limit": 50000,
},
},
},
})
if err != nil {
return err
}
_, err = grequests.Post(baseURL+"_snapshot/.utm_geoip/.utm-geoip/_restore?wait_for_completion=true", &grequests.RequestOptions{
JSON: map[string]interface{}{
"indices": ".utm-geoip",
},
})
if err != nil {
return err
}
return nil
}