serilog-contrib / serilog-sinks-elasticsearch

A Serilog sink that writes events to Elasticsearch
Apache License 2.0
434 stars 197 forks source link

v9.0.0 fails template creation with ES v7 with ElasticsearchClientException #518

Open AlexGoris-KasparSolutions opened 1 year ago

AlexGoris-KasparSolutions commented 1 year ago

Does this issue relate to a new feature or an existing bug?

What version of Serilog.Sinks.Elasticsearch is affected? Please list the related NuGet package. 9.0.0

What is the target framework and operating system? See target frameworks & net standard matrix.

Please describe the current behavior? When starting with an ES v7 server which doesn't have any serilog template configure, the sink tries to create the template, this fails with the following exception:

2023-03-08T10:12:49.7376289Z Failed to create the template. Elasticsearch.Net.ElasticsearchClientException: Request failed to execute. Call: Status code 400 from: PUT /_template/serilog-events-template?include_type_name=true. ServerError: Type: illegal_argument_exception Reason: "Malformed [mappings] section for type [dynamic_templates], should include an inner object describing the mapping"
   at Elasticsearch.Net.Transport`1.HandleElasticsearchClientException(RequestData data, Exception clientException, IElasticsearchResponse response)
   at Elasticsearch.Net.Transport`1.FinalizeResponse[TResponse](RequestData requestData, IRequestPipeline pipeline, List`1 seenExceptions, TResponse response)
   at Elasticsearch.Net.Transport`1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)
   at Elasticsearch.Net.ElasticLowLevelClient.DoRequest[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)
   at Elasticsearch.Net.NamespacedClientProxy.DoRequest[TResponse](HttpMethod post, String url, PostData body, IRequestParameters params)
   at Elasticsearch.Net.Specification.IndicesApi.LowLevelIndicesNamespace.PutTemplateForAll[TResponse](String name, PostData body, PutIndexTemplateRequestParameters requestParameters)
   at Serilog.Sinks.Elasticsearch.ElasticsearchSinkState.RegisterTemplateIfNeeded() in C:\Users\ag\workspaces\oss\serilog-sinks-elasticsearch\src\Serilog.Sinks.Elasticsearch\Sinks\ElasticSearch\ElasticsearchSinkState.cs:line 177

Please describe the expected behavior? Template creation should succeed without exceptions.

If the current behavior is a bug, please provide the steps to reproduce the issue and if possible a minimal demo of the problem Running the sample project with dotnet run, changing nothing other than the ConnectionStrings:elasticsearch parameter in appsettings.json against a local docker container running the sebp/elk:7.17.5 docker image.

Make sure you have the default serilog-events-template template deleted as if you've previously used 8.4.1 of this sink the template will already be there and won't be recreated.

nenadvicentic commented 1 year ago

@AlexGoris-KasparSolutions What configuration do you use for the sink in your .NET project when this error happens?

AlexGoris-KasparSolutions commented 1 year ago

@AlexGoris-KasparSolutions What configuration do you use for the sink in your .NET project when this error happens?

As described, I started from the sample project of this repo, only configured the ConnectionStrings:elasticsearch to point at my local elk stack (running sebp/elk:7.17.5) and started it with dotnet run

So the configuration is the one which is found in Program.cs line 33

nenadvicentic commented 1 year ago

@AlexGoris-KasparSolutions Thank you for the details. I've added few comments to your pull request: https://github.com/serilog-contrib/serilog-sinks-elasticsearch/pull/519#pullrequestreview-1400449741, if it's possible to round it up properly.