-
Notifications
You must be signed in to change notification settings - Fork 52
/
index_template_types.go
106 lines (91 loc) · 3.46 KB
/
index_template_types.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
package types
import (
"encoding/json"
"strconv"
"github.com/tidwall/gjson"
)
type IndexTemplateSpec struct {
TemplateName string `json:"-"`
IndexPatterns []string `json:"index_patterns,omitempty"`
Template TemplateSpec `json:"template,omitempty"`
Priority int `json:"priority,omitempty"`
}
type TemplateSpec struct {
Settings TemplateSettingsSpec `json:"settings,omitempty"`
Mappings TemplateMappingsSpec `json:"mappings,omitempty"`
}
type TemplateSettingsSpec struct {
NumberOfShards int `json:"number_of_shards,omitempty"`
NumberOfReplicas int `json:"number_of_replicas,omitempty"`
ISMPolicyID string `json:"opendistro.index_state_management.policy_id,omitempty"`
RolloverAlias string `json:"opendistro.index_state_management.rollover_alias,omitempty"`
DefaultPipeline string `json:"default_pipeline,omitempty"`
}
type TemplateMappingsSpec struct {
DateDetection *bool `json:"date_detection,omitempty"`
DynamicTemplates []map[string]DynamicTemplateSpec `json:"dynamic_templates,omitempty"`
Properties map[string]PropertySettings `json:"properties,omitempty"`
}
type PropertySettings struct {
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
Fields map[string]FieldsSpec `json:"fields,omitempty"`
IgnoreAbove int `json:"ignore_above,omitempty"`
Properties map[string]PropertySettings `json:"properties,omitempty"`
}
type DynamicTemplateSpec struct {
MatchMappingType string `json:"match_mapping_type,omitempty"`
Match string `json:"match,omitempty"`
UnMatch string `json:"unmatch,omitempty"`
PathMatch string `json:"path_match,omitempty"`
PathUnMatch string `json:"path_unmatch,omitempty"`
Mapping PropertySettings `json:"mapping,omitempty"`
}
type FieldsSpec struct {
Type string `json:"type,omitempty"`
IgnoreAbove int `json:"ignore_above,omitempty"`
}
type GetIndexTemplateObject struct {
Name string `json:"name,omitempty"`
Template IndexTemplateSpec `json:"index_template,omitempty"`
}
type GetIndexTemplateResponse struct {
IndexTemplates []GetIndexTemplateObject `json:"index_templates,omitempty"`
}
func (t *TemplateSettingsSpec) UnmarshalJSON(data []byte) error {
value := gjson.GetBytes(data, "index")
var err error
if value.Exists() {
t.DefaultPipeline = value.Get("default_pipeline").String()
t.RolloverAlias = value.Get("opendistro.index_state_management.rollover_alias").String()
t.ISMPolicyID = value.Get("opendistro.index_state_management.policy_id").String()
numReplicas := value.Get("number_of_replicas")
if numReplicas.Exists() {
t.NumberOfReplicas, err = strconv.Atoi(numReplicas.String())
if err != nil {
return err
}
}
numShards := value.Get("number_of_shards")
if numShards.Exists() {
t.NumberOfShards, err = strconv.Atoi(value.Get("number_of_shards").String())
if err != nil {
return err
}
}
return nil
}
type settings TemplateSettingsSpec
tmp := settings{}
err = json.Unmarshal(data, &tmp)
if err != nil {
return err
}
t.DefaultPipeline = tmp.DefaultPipeline
t.RolloverAlias = tmp.RolloverAlias
t.ISMPolicyID = tmp.ISMPolicyID
t.NumberOfReplicas = tmp.NumberOfReplicas
t.NumberOfShards = tmp.NumberOfShards
return nil
}