diff --git a/output/elasticsearch/output.go b/output/elasticsearch/output.go index 96dac26..3df7cd9 100644 --- a/output/elasticsearch/output.go +++ b/output/elasticsearch/output.go @@ -108,10 +108,17 @@ func (es *ElasticSearchOutput) Start() error { es.logger.Errorf("failed to serialize event: %v", err) continue } + var rawIndex string + // If the event metadata contains a raw_index field, attach + // that to the indexer item to override the global default. + if indexField := event.GetMetadata().GetData()["raw_index"]; indexField != nil { + rawIndex = indexField.GetStringValue() + } err = bi.Add( context.Background(), esutil.BulkIndexerItem{ Action: "index", + Index: rawIndex, Body: bytes.NewReader(serialized), OnSuccess: func(ctx context.Context, item esutil.BulkIndexerItem, res esutil.BulkIndexerResponseItem) { // TODO: update metrics