Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
fixes: v9.0.0 fails template creation with ES v7 with ElasticsearchCl…
Browse files Browse the repository at this point in the history
…ientException #518 (#533)

Co-authored-by: AlexGoris-KasparSolutions
  • Loading branch information
nenadvicentic authored May 10, 2023
1 parent 376ec1e commit fbba80b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -172,20 +170,16 @@ public void RegisterTemplateIfNeeded()
}
}

StringResponse result;
if (_versionManager.EffectiveVersion.Major < 8)
{
result = _client.Indices.PutTemplateForAll<StringResponse>(_templateName, GetTemplatePostData(),
var result = _versionManager.EffectiveVersion.Major switch
{
< 8 => _client.Indices.PutTemplateForAll<StringResponse>(_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<StringResponse>(_templateName, GetTemplatePostData());
}
_ => _client.Indices.PutTemplateV2ForAll<StringResponse>(_templateName, GetTemplatePostData()),
};

if (!result.Success)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit fbba80b

Please sign in to comment.