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

Commit a3c197b

Browse files
authored
Override type name if specified (#365)
Fixes a regression introduced in #356 We should override the TypeName if it's specified. Note that there are different defaults depending on how the options are created. - Created from configuration it defaults to `logevent` - Created from code it defaults to `_doc`
1 parent e7993aa commit a3c197b

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Fixed
9+
- Make sure TypeName is set to `_doc` when setting the template version to `ESv7`.
10+
The regression was introduced in `8.4.0`. #364
811

912
## [8.4.0] - 2020-09-19
1013
### Added

src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private ElasticsearchSinkState(ElasticsearchSinkOptions options)
7070
if (string.IsNullOrWhiteSpace(options.TemplateName)) throw new ArgumentException("options.TemplateName");
7171

7272
// Since TypeName is deprecated we shouldn't set it, if has been deliberately set to null.
73-
if (options.TypeName == null && options.AutoRegisterTemplateVersion == AutoRegisterTemplateVersion.ESv7)
73+
if (options.TypeName != null && options.AutoRegisterTemplateVersion == AutoRegisterTemplateVersion.ESv7)
7474
{
7575
options.TypeName = "_doc";
7676
}

test/Serilog.Sinks.Elasticsearch.Tests/BulkActionTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ public void DefaultBulkActionV7()
2525
const string expectedAction = @"{""index"":{""_type"":""_doc"",""_index"":""logs""}}";
2626
bulkJsonPieces[0].Should().Be(expectedAction);
2727
}
28+
29+
[Fact]
30+
public void BulkActionV7OverrideTypeName()
31+
{
32+
_options.IndexFormat = "logs";
33+
_options.TypeName = "logevent"; // This is the default value when creating the sink via configuration
34+
_options.AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7;
35+
_options.PipelineName = null;
36+
using (var sink = new ElasticsearchSink(_options))
37+
{
38+
sink.Emit(ADummyLogEvent());
39+
sink.Emit(ADummyLogEvent());
40+
}
41+
42+
var bulkJsonPieces = this.AssertSeenHttpPosts(_seenHttpPosts, 2, 1);
43+
const string expectedAction = @"{""index"":{""_type"":""_doc"",""_index"":""logs""}}";
44+
bulkJsonPieces[0].Should().Be(expectedAction);
45+
}
2846

2947
[Fact]
3048
public void DefaultBulkActionV8()

0 commit comments

Comments
 (0)