logagent-js icon indicating copy to clipboard operation
logagent-js copied to clipboard

Elasticsearch 8 output - Error code 400 - unknown parameter [ _type ]

Open vadym-dudar opened this issue 1 year ago • 1 comments

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?

vadym-dudar avatar Oct 28 '24 15:10 vadym-dudar

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')

fw42 avatar Jun 18 '25 21:06 fw42