11using System ;
2+ using System . Runtime . Serialization ;
23using Newtonsoft . Json ;
4+ using Newtonsoft . Json . Converters ;
35
46namespace Nest
57{
8+ /// <summary>
9+ /// A Dynamic template that defines custom mappings to be applied
10+ /// to dynamically added fields based on:
11+ /// <para />- the datatype detected by Elasticsearch, with <see cref="MatchMappingType"/>.
12+ /// <para />- the name of the field, with <see cref="Match"/> and <see cref="Unmatch"/> or <see cref="MatchPattern"/>.
13+ /// <para />- the full dotted path to the field, with <see cref="PathMatch"/> and <see cref="PathUnmatch"/>.
14+ /// </summary>
615 [ JsonObject ( MemberSerialization = MemberSerialization . OptIn ) ]
716 [ JsonConverter ( typeof ( ReadAsTypeJsonConverter < DynamicTemplate > ) ) ]
817 public interface IDynamicTemplate
918 {
19+ /// <summary>
20+ /// A pattern to match on the field name
21+ /// </summary>
1022 [ JsonProperty ( "match" ) ]
1123 string Match { get ; set ; }
1224
25+ /// <summary>
26+ /// Adjusts the behavior of <see cref="Match"/> such that it supports full
27+ /// Java regular expression matching on the field name instead of simple wildcards
28+ /// </summary>
29+ [ JsonProperty ( "match_pattern" ) ]
30+ MatchType ? MatchPattern { get ; set ; }
31+
32+ /// <summary>
33+ /// A pattern to exclude fields matched by <see cref="Match"/>
34+ /// </summary>
1335 [ JsonProperty ( "unmatch" ) ]
1436 string Unmatch { get ; set ; }
1537
38+ /// <summary>
39+ /// Matches on the datatype detected by dynamic field mapping,
40+ /// in other words, the datatype that Elasticsearch thinks the field should have.
41+ /// Only the following datatypes can be automatically detected: boolean, date, double,
42+ /// long, object, string. It also accepts * to match all datatypes.
43+ /// </summary>
1644 [ JsonProperty ( "match_mapping_type" ) ]
1745 string MatchMappingType { get ; set ; }
1846
47+ /// <summary>
48+ /// A pattern to match on the field name, which may be the full dotted path
49+ /// to the field name
50+ /// </summary>
1951 [ JsonProperty ( "path_match" ) ]
2052 string PathMatch { get ; set ; }
2153
54+ /// <summary>
55+ /// A pattern to exclude fields matched by <see cref="PathMatch"/>
56+ /// </summary>
2257 [ JsonProperty ( "path_unmatch" ) ]
2358 string PathUnmatch { get ; set ; }
2459
60+ /// <summary>
61+ /// The mapping to apply to matching fields
62+ /// </summary>
2563 [ JsonProperty ( "mapping" ) ]
2664 IProperty Mapping { get ; set ; }
2765 }
2866
67+ /// <inheritdoc />
2968 public class DynamicTemplate : IDynamicTemplate
3069 {
70+ /// <inheritdoc />
3171 public string Match { get ; set ; }
3272
73+ /// <inheritdoc />
74+ public MatchType ? MatchPattern { get ; set ; }
75+
76+ /// <inheritdoc />
3377 public string Unmatch { get ; set ; }
3478
79+ /// <inheritdoc />
3580 public string MatchMappingType { get ; set ; }
3681
82+ /// <inheritdoc />
3783 public string PathMatch { get ; set ; }
3884
85+ /// <inheritdoc />
3986 public string PathUnmatch { get ; set ; }
4087
88+ /// <inheritdoc />
4189 public IProperty Mapping { get ; set ; }
4290 }
4391
92+ /// <inheritdoc cref="IDynamicTemplate"/>
4493 public class DynamicTemplateDescriptor < T > : DescriptorBase < DynamicTemplateDescriptor < T > , IDynamicTemplate > , IDynamicTemplate
4594 where T : class
4695 {
4796 string IDynamicTemplate . Match { get ; set ; }
97+ MatchType ? IDynamicTemplate . MatchPattern { get ; set ; }
4898 string IDynamicTemplate . Unmatch { get ; set ; }
4999 string IDynamicTemplate . MatchMappingType { get ; set ; }
50100 string IDynamicTemplate . PathMatch { get ; set ; }
51101 string IDynamicTemplate . PathUnmatch { get ; set ; }
52102 IProperty IDynamicTemplate . Mapping { get ; set ; }
53103
104+ /// <inheritdoc cref="IDynamicTemplate.Match"/>
54105 public DynamicTemplateDescriptor < T > Match ( string match ) => Assign ( a => a . Match = match ) ;
55106
107+ /// <inheritdoc cref="IDynamicTemplate.MatchPattern"/>
108+ public DynamicTemplateDescriptor < T > MatchPattern ( MatchType ? matchPattern ) => Assign ( a => a . MatchPattern = matchPattern ) ;
109+
110+ /// <inheritdoc cref="IDynamicTemplate.Unmatch"/>
56111 public DynamicTemplateDescriptor < T > Unmatch ( string unMatch ) => Assign ( a => a . Unmatch = unMatch ) ;
57112
113+ /// <inheritdoc cref="IDynamicTemplate.MatchMappingType"/>
58114 public DynamicTemplateDescriptor < T > MatchMappingType ( string matchMappingType ) => Assign ( a => a . MatchMappingType = matchMappingType ) ;
59115
116+ /// <inheritdoc cref="IDynamicTemplate.PathMatch"/>
60117 public DynamicTemplateDescriptor < T > PathMatch ( string pathMatch ) => Assign ( a => a . PathMatch = pathMatch ) ;
61118
119+ /// <inheritdoc cref="IDynamicTemplate.PathUnmatch"/>
62120 public DynamicTemplateDescriptor < T > PathUnmatch ( string pathUnmatch ) => Assign ( a => a . PathUnmatch = pathUnmatch ) ;
63121
122+ /// <inheritdoc cref="IDynamicTemplate.Mapping"/>
64123 public DynamicTemplateDescriptor < T > Mapping ( Func < SingleMappingSelector < T > , IProperty > mappingSelector ) => Assign ( a => a . Mapping = mappingSelector ? . Invoke ( new SingleMappingSelector < T > ( ) ) ) ;
65124 }
66- }
125+
126+ /// <summary>
127+ /// Dynamic match pattern type
128+ /// </summary>
129+ [ JsonConverter ( typeof ( StringEnumConverter ) ) ]
130+ public enum MatchType
131+ {
132+ /// <summary>
133+ /// Simple matching with wildcards
134+ /// </summary>
135+ [ EnumMember ( Value = "simple" ) ]
136+ Simple ,
137+
138+ /// <summary>
139+ /// Regular expression matching
140+ /// </summary>
141+ [ EnumMember ( Value = "regex" ) ]
142+ Regex
143+ }
144+ }
0 commit comments