This repository has been archived by the owner on Jun 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get rid of 'deprecated' warnings in Elastic 5.6.2 (#142)
* Get rid of 'deprecated' warnings in Elastic 5.6.2 Our Elastic 5.6.2 logs are flooded with below errors: The [string] field is deprecated, please use [text] or [keyword] [omit_norms] is deprecated, please use [norms] instead with the opposite boolean value Updated the schema following https://www.elastic.co/blog/strings-are-dead-long-live-strings * Update ElasticsearchSinkState.cs * Update template.json * Update ElasticsearchSinkState.cs * Update template.json * add template provider * fix unit tests
- Loading branch information
1 parent
cb9f3e2
commit 4d2425b
Showing
10 changed files
with
757 additions
and
124 deletions.
There are no files selected for viewing
336 changes: 336 additions & 0 deletions
336
src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchTemplateProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,336 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Serilog.Sinks.Elasticsearch | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public enum AutoRegisterTemplateVersion | ||
{ | ||
/// <summary> | ||
/// Elasticsearch version <= 2.4 | ||
/// </summary> | ||
ESv2 = 0, | ||
/// <summary> | ||
/// Elasticsearch version <= version 5.6 | ||
/// </summary> | ||
ESv5 = 1, | ||
/// <summary> | ||
/// Elasticsearch version >= version 6.0 | ||
/// </summary> | ||
ESv6 = 2 | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class ElasticSearchTemplateProvider | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="settings"></param> | ||
/// <param name="templateMatchString"></param> | ||
/// <param name="version"></param> | ||
/// <returns></returns> | ||
public static object GetTemplate( | ||
Dictionary<string, string> settings, | ||
string templateMatchString, | ||
AutoRegisterTemplateVersion version = AutoRegisterTemplateVersion.ESv2) | ||
{ | ||
switch (version) | ||
{ | ||
case AutoRegisterTemplateVersion.ESv5: | ||
return GetTemplateESv5(settings, templateMatchString); | ||
case AutoRegisterTemplateVersion.ESv6: | ||
return GetTemplateESv6(settings, templateMatchString); | ||
case AutoRegisterTemplateVersion.ESv2: | ||
return GetTemplateESv2(settings, templateMatchString); | ||
default: | ||
throw new ArgumentOutOfRangeException(nameof(version), version, null); | ||
} | ||
} | ||
|
||
private static object GetTemplateESv6( | ||
Dictionary<string, string> settings, | ||
string templateMatchString) | ||
{ | ||
return new | ||
{ | ||
template = templateMatchString, | ||
settings = settings, | ||
mappings = new | ||
{ | ||
_default_ = new | ||
{ | ||
dynamic_templates = new List<Object> | ||
{ | ||
//when you use serilog as an adaptor for third party frameworks | ||
//where you have no control over the log message they typically | ||
//contain {0} ad infinitum, we force numeric property names to | ||
//contain strings by default. | ||
{ | ||
new | ||
{ | ||
numerics_in_fields = new | ||
{ | ||
path_match = @"fields\.[\d+]$", | ||
match_pattern = "regex", | ||
mapping = new | ||
{ | ||
type = "text", | ||
index = true, | ||
norms = false | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
new | ||
{ | ||
string_fields = new | ||
{ | ||
match = "*", | ||
match_mapping_type = "string", | ||
mapping = new | ||
{ | ||
type = "text", | ||
index = true, | ||
norms = false, | ||
fields = new | ||
{ | ||
raw = new | ||
{ | ||
type = "keyword", | ||
index = true, | ||
ignore_above = 256 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
properties = new Dictionary<string, object> | ||
{ | ||
{"message", new {type = "text", index = "analyzed"}}, | ||
{ | ||
"exceptions", new | ||
{ | ||
type = "nested", | ||
properties = new Dictionary<string, object> | ||
{ | ||
{"Depth", new {type = "integer"}}, | ||
{"RemoteStackIndex", new {type = "integer"}}, | ||
{"HResult", new {type = "integer"}}, | ||
{"StackTraceString", new {type = "text", index = "analyzed"}}, | ||
{"RemoteStackTraceString", new {type = "text", index = "analyzed"}}, | ||
{ | ||
"ExceptionMessage", new | ||
{ | ||
type = "object", | ||
properties = new Dictionary<string, object> | ||
{ | ||
{"MemberType", new {type = "integer"}}, | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
private static object GetTemplateESv5( | ||
Dictionary<string, string> settings, | ||
string templateMatchString) | ||
{ | ||
return new | ||
{ | ||
template = templateMatchString, | ||
settings = settings, | ||
mappings = new | ||
{ | ||
_default_ = new | ||
{ | ||
_all = new { enabled = true, norms = false }, | ||
dynamic_templates = new List<Object> | ||
{ | ||
//when you use serilog as an adaptor for third party frameworks | ||
//where you have no control over the log message they typically | ||
//contain {0} ad infinitum, we force numeric property names to | ||
//contain strings by default. | ||
{ | ||
new | ||
{ | ||
numerics_in_fields = new | ||
{ | ||
path_match = @"fields\.[\d+]$", | ||
match_pattern = "regex", | ||
mapping = new | ||
{ | ||
type = "text", | ||
index = true, | ||
norms = false | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
new | ||
{ | ||
string_fields = new | ||
{ | ||
match = "*", | ||
match_mapping_type = "string", | ||
mapping = new | ||
{ | ||
type = "text", | ||
index = true, | ||
norms = false, | ||
fields = new | ||
{ | ||
raw = new | ||
{ | ||
type = "keyword", | ||
index = true, | ||
ignore_above = 256 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
properties = new Dictionary<string, object> | ||
{ | ||
{"message", new {type = "text", index = "analyzed"}}, | ||
{ | ||
"exceptions", new | ||
{ | ||
type = "nested", | ||
properties = new Dictionary<string, object> | ||
{ | ||
{"Depth", new {type = "integer"}}, | ||
{"RemoteStackIndex", new {type = "integer"}}, | ||
{"HResult", new {type = "integer"}}, | ||
{"StackTraceString", new {type = "text", index = "analyzed"}}, | ||
{"RemoteStackTraceString", new {type = "text", index = "analyzed"}}, | ||
{ | ||
"ExceptionMessage", new | ||
{ | ||
type = "object", | ||
properties = new Dictionary<string, object> | ||
{ | ||
{"MemberType", new {type = "integer"}}, | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
private static object GetTemplateESv2( | ||
Dictionary<string, string> settings, | ||
string templateMatchString) | ||
{ | ||
return new | ||
{ | ||
template = templateMatchString, | ||
settings = settings, | ||
mappings = new | ||
{ | ||
_default_ = new | ||
{ | ||
_all = new { enabled = true, omit_norms = true }, | ||
dynamic_templates = new List<Object> | ||
{ | ||
//when you use serilog as an adaptor for third party frameworks | ||
//where you have no control over the log message they typically | ||
//contain {0} ad infinitum, we force numeric property names to | ||
//contain strings by default. | ||
{ | ||
new | ||
{ | ||
numerics_in_fields = new | ||
{ | ||
path_match = @"fields\.[\d+]$", | ||
match_pattern = "regex", | ||
mapping = new | ||
{ | ||
type = "string", | ||
index = "analyzed", | ||
omit_norms = true | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
new | ||
{ | ||
string_fields = new | ||
{ | ||
match = "*", | ||
match_mapping_type = "string", | ||
mapping = new | ||
{ | ||
type = "string", | ||
index = "analyzed", | ||
omit_norms = true, | ||
fields = new | ||
{ | ||
raw = new | ||
{ | ||
type = "string", | ||
index = "not_analyzed", | ||
ignore_above = 256 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
properties = new Dictionary<string, object> | ||
{ | ||
{"message", new {type = "string", index = "analyzed"}}, | ||
{ | ||
"exceptions", new | ||
{ | ||
type = "nested", | ||
properties = new Dictionary<string, object> | ||
{ | ||
{"Depth", new {type = "integer"}}, | ||
{"RemoteStackIndex", new {type = "integer"}}, | ||
{"HResult", new {type = "integer"}}, | ||
{"StackTraceString", new {type = "string", index = "analyzed"}}, | ||
{"RemoteStackTraceString", new {type = "string", index = "analyzed"}}, | ||
{ | ||
"ExceptionMessage", new | ||
{ | ||
type = "object", | ||
properties = new Dictionary<string, object> | ||
{ | ||
{"MemberType", new {type = "integer"}}, | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.