logagent-js
logagent-js copied to clipboard
Elasticsearch 8 output - Error code 400 - unknown parameter [ _type ]
https://www.elastic.co/guide/en/elasticsearch/reference/7.17/removal-of-types.html Elasticsearch drop mapping types
Now, when I try send logs to elasticsearch, I got an error:
{ "error": { "root_cause": [ { "type": "illegal_argument_exception", "reason": "Action/metadata line [1] contains an unknown parameter [_type]" } ], "type": "illegal_argument_exception", "reason": "Action/metadata line [1] contains an unknown parameter [_type]" }, "status": 400 }
How I can override this?
Not sure if it's a good fix (probably not backwards compatible), but this seems to work:
@@ -416,9 +416,9 @@ Logsene.prototype.log = function (level, message, fields, callback) {
}
if (elasticsearchDocId !== null) {
- this.bulkReq.write(stringifySafe({ 'index': { '_index': _index, '_id': String(elasticsearchDocId), '_type': type || this.type } }) + '\n')
+ this.bulkReq.write(stringifySafe({ 'index': { '_index': _index, '_id': String(elasticsearchDocId) } }) + '\n')
} else {
- this.bulkReq.write(stringifySafe({ 'index': { '_index': _index, '_type': type || this.type } }) + '\n')
+ this.bulkReq.write(stringifySafe({ 'index': { '_index': _index } }) + '\n')
}
this.bulkReq.write(stringifySafe(msg) + '\n')