in pkg/esoutput/esoutput.go [187:211]
func (o *Output) Start() error {
indexName := o.config.IndexName.String
res, err := o.client.Indices.Create(indexName, o.client.Indices.Create.WithBody(bytes.NewReader(mapping)))
if err != nil {
return err
}
// 400 usually happens when the index already exists, which is ok for our purposes.
if res.StatusCode > 400 {
body, err := io.ReadAll(res.Body)
if err != nil {
return fmt.Errorf("could not read response after failure to create index %s: %v", indexName, err)
}
return fmt.Errorf("could not create index %s: %s", indexName, body)
}
res.Body.Close()
if periodicFlusher, err := output.NewPeriodicFlusher(time.Duration(o.config.FlushPeriod.Duration), o.flush); err != nil {
return err
} else {
o.periodicFlusher = periodicFlusher
}
o.logger.Debugf("Elasticsearch: starting writing to index %s", indexName)
return nil
}