diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs index 540e0d0a..ef8cbb0c 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs @@ -172,20 +172,17 @@ public void RegisterTemplateIfNeeded() } } - StringResponse result; - if (_versionManager.EffectiveVersion.Major < 8) - { - result = _client.Indices.PutTemplateForAll(_templateName, GetTemplatePostData(), + var result = _versionManager.EffectiveVersion.Major switch + { + < 7 => _client.Indices.PutTemplateForAll(_templateName, GetTemplatePostData(), new PutIndexTemplateRequestParameters { IncludeTypeName = IncludeTypeName ? true : (bool?)null - }); - } - else - { + }), + < 8 => _client.Indices.PutTemplateForAll(_templateName, GetTemplatePostData()), // Default to version 8 API - result = _client.Indices.PutTemplateV2ForAll(_templateName, GetTemplatePostData()); - } + _ => _client.Indices.PutTemplateV2ForAll(_templateName, GetTemplatePostData()), + }; if (!result.Success) {