Skip to content

Commit 5d9b565

Browse files
fix: logs mappings (#125)
* fix: add mappings for logs * fix: mappings for rollover indices * Update utils.go Co-authored-by: Siddharth Kothari <sids.aquarius@gmail.com>
1 parent f775790 commit 5d9b565

3 files changed

Lines changed: 486 additions & 2 deletions

File tree

plugins/logs/dao.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ func initPlugin(alias, config string) (*elasticsearch, error) {
4242
}
4343

4444
replicas := util.GetReplicas()
45-
settings := fmt.Sprintf(config, alias, util.HiddenIndexSettings(), replicas)
45+
46+
settings := fmt.Sprintf(config, alias, util.HiddenIndexSettings(), replicas, LogsMappings)
47+
48+
if util.GetVersion() == 6 {
49+
mappings := fmt.Sprintf(`{"_doc": %s}`, LogsMappings)
50+
settings = fmt.Sprintf(config, alias, util.HiddenIndexSettings(), replicas, mappings)
51+
}
4652
// Meta index doesn't exist, create one
4753
indexName := alias + `-000001`
4854
// this works for ES6 client as well
@@ -111,10 +117,19 @@ func (es *elasticsearch) rolloverIndexJob(alias string) {
111117
settingsString := fmt.Sprintf(`{%s "index.number_of_shards": 1, "index.number_of_replicas": %d}`, util.HiddenIndexSettings(), util.GetReplicas())
112118
settings := make(map[string]interface{})
113119
json.Unmarshal([]byte(settingsString), &settings)
120+
121+
mappingString := LogsMappings
122+
if util.GetVersion() == 6 {
123+
mappingString = fmt.Sprintf(`{"_doc": %s}`, LogsMappings)
124+
}
125+
126+
mappings := make(map[string]interface{})
127+
json.Unmarshal([]byte(mappingString), &mappings)
114128
rolloverService, err := es7.NewIndicesRolloverService(util.GetClient7()).
115129
Alias(alias).
116130
Conditions(rolloverConditions).
117131
Settings(settings).
132+
Mappings(mappings).
118133
Do(ctx)
119134
if err != nil {
120135
log.Printf(logTag, "error while creating a rollover service %s %v", alias, err)

plugins/logs/logs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ const (
2929
%s
3030
"index.number_of_shards": 1,
3131
"index.number_of_replicas": %d
32-
}
32+
},
33+
"mappings": %s
3334
}`
3435
rolloverConfig = `{
3536
"max_age": "%s",

0 commit comments

Comments
 (0)