serilog-sinks-elasticsearch icon indicating copy to clipboard operation
serilog-sinks-elasticsearch copied to clipboard

Add Support for OpenSearch.

Open suredanish opened this issue 1 year ago • 0 comments
trafficstars

Summary

serilog.sinks.elasticsearch 8.4.1 supports OpenSearch but for OpenSearch to work you need to set TypeName option set to null. and that can only be configured through code and not through appsettings.json. This error was fixed in version 9 but version 9 does not support OpenSearch

If TypeName option is not set to null below error occurs:
Caught exception while preforming bulk operation to Elasticsearch: Elasticsearch.Net.ElasticsearchClientException: Request failed to execute.
Call: Status code 400 from: POST /_bulk. ServerError: Type: illegal_argument_exception Reason: "Action/metadata line [1] contains an unknown
parameter [_type]"

Steps to reproduce

// Program.cs

using Serilog;

var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog( (context, config) => { config.ReadFrom.Configuration(context.Configuration); } );
var app = builder.Build();

app.MapGet("/", () => "Hello World!");

app.Run();

{
  "_comment1": "This is 'appsettings.json' file",
  "Serilog": {
    "Using": [ "Serilog.Sinks.Elasticsearch" ],
    "WriteTo": [
      {
        "Name": "Elasticsearch",
        "Args": {
          "nodeUris": "http://localhost:9200",
          "typeName": null,
          "autoRegisterTemplate": true,
          "autoRegisterTemplateVersion": "ESv7"
        }
      }
    ],
    "Properties": {
      "Application": "bossport"
    }
  }
}

Spin OpenSearch Container In docker
OpenSearch docker command:
docker run -d -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" -e "DISABLE_SECURITY_PLUGIN=true" --name opensearch opensearchproject/opensearch:latest

OpenSearch Dashboard docker command:

docker run -d -p 5602:5601 -e 'OPENSEARCH_HOSTS=["http://localhost:9200"]' -e 'DISABLE_SECURITY_DASHBOARDS_PLUGIN=true' --name opensearch-dashboard opensearchproject/opensearch-dashboards

What is the current bug behavior?

"typeName": null does not get configured via appsettings.

suredanish avatar Nov 22 '23 16:11 suredanish