diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs index 540e0d0a..a46f0d2a 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs @@ -52,8 +52,6 @@ public static ElasticsearchSinkState Create(ElasticsearchSinkOptions options) private readonly ElasticsearchVersionManager _versionManager; - private bool IncludeTypeName => _versionManager.EffectiveVersion.Major >= 7; - public ElasticsearchSinkOptions Options => _options; public IElasticLowLevelClient Client => _client; public ITextFormatter Formatter => _formatter; @@ -172,20 +170,16 @@ public void RegisterTemplateIfNeeded() } } - StringResponse result; - if (_versionManager.EffectiveVersion.Major < 8) - { - result = _client.Indices.PutTemplateForAll(_templateName, GetTemplatePostData(), + var result = _versionManager.EffectiveVersion.Major switch + { + < 8 => _client.Indices.PutTemplateForAll(_templateName, GetTemplatePostData(), new PutIndexTemplateRequestParameters { - IncludeTypeName = IncludeTypeName ? true : (bool?)null - }); - } - else - { + IncludeTypeName = _versionManager.EffectiveVersion.Major < 7 ? true : null + }), // Default to version 8 API - result = _client.Indices.PutTemplateV2ForAll(_templateName, GetTemplatePostData()); - } + _ => _client.Indices.PutTemplateV2ForAll(_templateName, GetTemplatePostData()), + }; if (!result.Success) { diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SendsTemplateTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SendsTemplateTests.cs index 9e86c119..7cd76552 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SendsTemplateTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SendsTemplateTests.cs @@ -42,6 +42,7 @@ public void TemplatePutToCorrectUrl() { var uri = _templatePut.Item1; uri.AbsolutePath.Should().Be("/_template/serilog-events-template"); + uri.Query.Should().Be(string.Empty); } } } \ No newline at end of file diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv6TemplateTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv6TemplateTests.cs index fc3018ac..377d7933 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv6TemplateTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv6TemplateTests.cs @@ -43,6 +43,7 @@ public void TemplatePutToCorrectUrl() { var uri = _templatePut.Item1; uri.AbsolutePath.Should().Be("/_template/serilog-events-template"); + uri.Query.Should().Be("?include_type_name=true"); } } } \ No newline at end of file diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv7TemplateTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv7TemplateTests.cs index e8d695f6..5a4059a7 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv7TemplateTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv7TemplateTests.cs @@ -44,6 +44,7 @@ public void TemplatePutToCorrectUrl() { var uri = _templatePut.Item1; uri.AbsolutePath.Should().Be("/_template/serilog-events-template"); + uri.Query.Should().Be(string.Empty); } } } \ No newline at end of file diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv8TemplateTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv8TemplateTests.cs index 22de419f..7d3b1f5b 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv8TemplateTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv8TemplateTests.cs @@ -43,6 +43,7 @@ public void TemplatePutToCorrectUrl() { var uri = _templatePut.Item1; uri.AbsolutePath.Should().Be("/_index_template/serilog-events-template"); + uri.Query.Should().Be(string.Empty); } } } \ No newline at end of file