Skip to content

Commit 1a731d6

Browse files
committed
support date pattern in AWS Elasticsearch index name
1 parent 9b98c66 commit 1a731d6

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

lib/plugins/output/aws-elasticsearch.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,23 @@ function OutputAwsElasticsearch (config, eventEmitter) {
4343
}
4444

4545
OutputAwsElasticsearch.prototype.eventHandler = function (data, context) {
46+
// support for time-based index patterns
47+
var index = this.config.index
48+
index = index.replace(/YYYY|MM|DD/g, function (match) {
49+
if (match === 'YYYY') {
50+
return '' + data['@timestamp'].getFullYear()
51+
}
52+
if (match === 'MM') {
53+
return ('0' + (data['@timestamp'].getMonth() + 1)).substr(-2)
54+
}
55+
if (match === 'DD') {
56+
return ('0' + data['@timestamp'].getDate()).substr(-2)
57+
}
58+
return match
59+
})
60+
4661
var obj = {
47-
index: this.config.index,
62+
index: index,
4863
type: this.config.type,
4964
body: data
5065
}

0 commit comments

Comments
 (0)