diff --git a/global.json b/global.json
index 341f9fea..99e7444e 100644
--- a/global.json
+++ b/global.json
@@ -1,5 +1,5 @@
{
"sdk": {
- "version": "2.1.4"
+ "version": "2.1.500"
}
}
\ No newline at end of file
diff --git a/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.Elasticsearch.csproj b/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.Elasticsearch.csproj
index b1d79191..d2e3559f 100644
--- a/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.Elasticsearch.csproj
+++ b/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.Elasticsearch.csproj
@@ -33,7 +33,6 @@
-
@@ -43,7 +42,16 @@
+
+
+
+
+
+
+
+
+
1591;1701;1702
diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchSink.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchSink.cs
index 0bb75390..d89136fd 100644
--- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchSink.cs
+++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchSink.cs
@@ -71,7 +71,7 @@ protected override void EmitBatch(IEnumerable events)
var items = result.Body["items"];
foreach (var item in items)
{
- if (item.index != null && item.index.error != null)
+ if (item["index"] != null && item["index"]["error"] != null)
{
var e = events.ElementAt(indexer);
if (_state.Options.EmitEventFailure.HasFlag(EmitEventFailureHandling.WriteToSelfLog))
@@ -80,8 +80,8 @@ protected override void EmitBatch(IEnumerable events)
SelfLog.WriteLine(
"Failed to store event with template '{0}' into Elasticsearch. Elasticsearch reports for index {1} the following: {2}",
e.MessageTemplate,
- item.index._index,
- item.index.error);
+ item["index"]["_index"],
+ _state.Serialize(item["index"]["error"]));
}
if (_state.Options.EmitEventFailure.HasFlag(EmitEventFailureHandling.WriteToFailureSink) &&
diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchTemplateProvider.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchTemplateProvider.cs
index 3847a4b0..0325992b 100644
--- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchTemplateProvider.cs
+++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchTemplateProvider.cs
@@ -19,7 +19,11 @@ public enum AutoRegisterTemplateVersion
///
/// Elasticsearch version >= version 6.0
///
- ESv6 = 2
+ ESv6 = 2,
+ ///
+ /// Elasticsearch version >= version 7.0
+ ///
+ ESv7 = 3
}
///
@@ -45,6 +49,8 @@ public static object GetTemplate(
return GetTemplateESv5(settings, templateMatchString);
case AutoRegisterTemplateVersion.ESv6:
return GetTemplateESv6(settings, templateMatchString);
+ case AutoRegisterTemplateVersion.ESv7:
+ return GetTemplateESv7(settings, templateMatchString);
case AutoRegisterTemplateVersion.ESv2:
return GetTemplateESv2(settings, templateMatchString);
default:
@@ -52,6 +58,96 @@ public static object GetTemplate(
}
}
+ private static object GetTemplateESv7(
+ Dictionary settings,
+ string templateMatchString)
+ {
+ return new
+ {
+ index_patterns = new[] { templateMatchString },
+ settings = settings,
+ mappings = new
+ {
+ dynamic_templates = new List
+
@@ -39,7 +41,6 @@
-
@@ -61,8 +62,19 @@
+
+
+
+
+
+
+
+
+
+
+
$(DefineConstants);DOTNETCORE;NO_SERIALIZATION
diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv7TemplateTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv7TemplateTests.cs
new file mode 100644
index 00000000..6180ed44
--- /dev/null
+++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv7TemplateTests.cs
@@ -0,0 +1,66 @@
+using System;
+using System.Reflection;
+using FluentAssertions;
+using Newtonsoft.Json.Linq;
+using Xunit;
+
+namespace Serilog.Sinks.Elasticsearch.Tests.Templating
+{
+ public class Sendsv7TemplateTests : ElasticsearchSinkTestsBase
+ {
+ private readonly Tuple _templatePut;
+
+ public Sendsv7TemplateTests()
+ {
+ _options.AutoRegisterTemplate = true;
+ _options.AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7;
+
+ var loggerConfig = new LoggerConfiguration()
+ .MinimumLevel.Debug()
+ .Enrich.WithMachineName()
+ .WriteTo.ColoredConsole()
+ .WriteTo.Elasticsearch(_options);
+
+ var logger = loggerConfig.CreateLogger();
+ using (logger as IDisposable)
+ {
+ logger.Error("Test exception. Should not contain an embedded exception object.");
+ }
+
+ this._seenHttpPosts.Should().NotBeNullOrEmpty().And.HaveCount(1);
+ this._seenHttpPuts.Should().NotBeNullOrEmpty().And.HaveCount(1);
+ _templatePut = this._seenHttpPuts[0];
+ }
+
+ [Fact]
+ public void ShouldRegisterTheCorrectTemplateOnRegistration()
+ {
+
+ var method = typeof(Sendsv7TemplateTests).GetMethod(nameof(ShouldRegisterTheCorrectTemplateOnRegistration));
+ JsonEquals(_templatePut.Item2, method, "template_v7.json");
+ }
+
+ [Fact]
+ public void TemplatePutToCorrectUrl()
+ {
+ var uri = _templatePut.Item1;
+ uri.AbsolutePath.Should().Be("/_template/serilog-events-template");
+ }
+
+ protected void JsonEquals(string json, MethodBase method, string fileName = null)
+ {
+#if DOTNETCORE
+ var assembly = typeof(Sendsv7TemplateTests).GetTypeInfo().Assembly;
+#else
+ var assembly = Assembly.GetExecutingAssembly();
+#endif
+ var expected = TestDataHelper.ReadEmbeddedResource(assembly, fileName ?? "template.json");
+
+ var nJson = JObject.Parse(json);
+ var nOtherJson = JObject.Parse(expected);
+ var equals = JToken.DeepEquals(nJson, nOtherJson);
+ if (equals) return;
+ expected.Should().BeEquivalentTo(json);
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v7.json b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v7.json
new file mode 100644
index 00000000..585f5323
--- /dev/null
+++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v7.json
@@ -0,0 +1,75 @@
+{
+ "index_patterns": [ "logstash-*" ],
+ "settings": {
+ "index.refresh_interval": "5s"
+ },
+ "mappings": {
+ "dynamic_templates": [
+ {
+ "numerics_in_fields": {
+ "path_match": "fields\\.[\\d+]$",
+ "match_pattern": "regex",
+ "mapping": {
+ "type": "text",
+ "index": true,
+ "norms": false
+ }
+ }
+ },
+ {
+ "string_fields": {
+ "match": "*",
+ "match_mapping_type": "string",
+ "mapping": {
+ "type": "text",
+ "index": true,
+ "norms": false,
+ "fields": {
+ "raw": {
+ "type": "keyword",
+ "index": true,
+ "ignore_above": 256
+ }
+ }
+ }
+ }
+ }
+ ],
+ "properties": {
+ "message": {
+ "type": "text",
+ "index": "true"
+ },
+ "exceptions": {
+ "type": "nested",
+ "properties": {
+ "Depth": {
+ "type": "integer"
+ },
+ "RemoteStackIndex": {
+ "type": "integer"
+ },
+ "HResult": {
+ "type": "integer"
+ },
+ "StackTraceString": {
+ "type": "text",
+ "index": "true"
+ },
+ "RemoteStackTraceString": {
+ "type": "text",
+ "index": "true"
+ },
+ "ExceptionMessage": {
+ "type": "object",
+ "properties": {
+ "MemberType": {
+ "type": "integer"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}