haraka / haraka-plugin-elasticsearch

Ship Haraka log info directly to Elasticsearch
https://www.npmjs.com/package/haraka-plugin-elasticsearch
MIT License
5 stars 5 forks source link

Elasticsearch 8.x compatibility #50

Closed sriccio closed 9 months ago

sriccio commented 9 months ago

Hi,

I wasn't able to use the plugin as it is against an elasticsearch 8.x cluster.

The result is an error message when the plugin attempts to push the data to the cluster.

[elasticsearch] {"error":"Content-Type header [text/plain] is not supported","status":406}

It looks like the arguments to create() have changed between 7.x and 8.x elasticsearch JS client.

https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/7.17/api-reference.html#_create vs https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/8.11/api-reference.html#_create

Main issue is that the type argument is gone and deprecated in 8.x

Also body is replaced by document in the doc and directly uses an object, so no need to stringify as it will switch the content type to text instead of json.

It seems though that body still works with 8.x. It was probably added as an alias for some kind of backward compat.

Should I submit a PR with the required changes ? I'm not sure though if this will break compatibility with older major versions of ES.

But afaik, anyway the JS client for elasticsearch 8.x will not work on a 7.x or earlier cluster....