From 056835b331b0d611f8be730207d28d26cbe81ae3 Mon Sep 17 00:00:00 2001 From: Alex Goris Date: Wed, 8 Mar 2023 11:03:44 +0100 Subject: [PATCH] fix: Don't set include_type_name query param for ES v7 template creation call --- .../ElasticSearch/ElasticsearchSinkState.cs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) 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) {