elastic: pre-declare index mapping

pull/113/head
Aloïs Micard 3 years ago
parent 33ba6b4e7d
commit 2d6beb26ce
No known key found for this signature in database
GPG Key ID: 1A0EB82F071F5EFE

@ -11,6 +11,51 @@ import (
var resourcesIndex = "resources"
const mapping = `
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"dynamic": false,
"properties": {
"body": {
"type": "text"
},
"description": {
"type": "text"
},
"url": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"time": {
"type": "date"
},
"title": {
"type": "text"
},
"headers": {
"properties": {
"server": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}
}
}`
type elasticSearchDB struct {
client *elastic.Client
}
@ -139,7 +184,9 @@ func setupElasticSearch(ctx context.Context, es *elastic.Client) error {
}
if !exist {
log.Debug().Str("index", resourcesIndex).Msg("Creating missing index")
if _, err := es.CreateIndex(resourcesIndex).Do(ctx); err != nil {
q := es.CreateIndex(resourcesIndex).BodyString(mapping)
if _, err := q.Do(ctx); err != nil {
return err
}
}

@ -143,6 +143,7 @@ func execute(process Process) cli.ActionFunc {
// Custom setup
if err := process.Initialize(provider); err != nil {
log.Err(err).Msg("error while initializing app")
return err
}
@ -156,6 +157,10 @@ func execute(process Process) cli.ActionFunc {
for _, subscriberDef := range process.Subscribers() {
if err := sub.Subscribe(subscriberDef.Exchange, subscriberDef.Queue, subscriberDef.Handler); err != nil {
log.Err(err).
Str("exchange", subscriberDef.Exchange).
Str("queue", subscriberDef.Queue).
Msg("error while subscribing")
return err
}
}

Loading…
Cancel
Save