1
1
using System ;
2
+ using System . Runtime . Serialization ;
2
3
using Newtonsoft . Json ;
4
+ using Newtonsoft . Json . Converters ;
3
5
4
6
namespace Nest
5
7
{
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>
6
15
[ JsonObject ( MemberSerialization = MemberSerialization . OptIn ) ]
7
16
[ JsonConverter ( typeof ( ReadAsTypeJsonConverter < DynamicTemplate > ) ) ]
8
17
public interface IDynamicTemplate
9
18
{
19
+ /// <summary>
20
+ /// A pattern to match on the field name
21
+ /// </summary>
10
22
[ JsonProperty ( "match" ) ]
11
23
string Match { get ; set ; }
12
24
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>
13
35
[ JsonProperty ( "unmatch" ) ]
14
36
string Unmatch { get ; set ; }
15
37
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>
16
44
[ JsonProperty ( "match_mapping_type" ) ]
17
45
string MatchMappingType { get ; set ; }
18
46
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>
19
51
[ JsonProperty ( "path_match" ) ]
20
52
string PathMatch { get ; set ; }
21
53
54
+ /// <summary>
55
+ /// A pattern to exclude fields matched by <see cref="PathMatch"/>
56
+ /// </summary>
22
57
[ JsonProperty ( "path_unmatch" ) ]
23
58
string PathUnmatch { get ; set ; }
24
59
60
+ /// <summary>
61
+ /// The mapping to apply to matching fields
62
+ /// </summary>
25
63
[ JsonProperty ( "mapping" ) ]
26
64
IProperty Mapping { get ; set ; }
27
65
}
28
66
67
+ /// <inheritdoc />
29
68
public class DynamicTemplate : IDynamicTemplate
30
69
{
70
+ /// <inheritdoc />
31
71
public string Match { get ; set ; }
32
72
73
+ /// <inheritdoc />
74
+ public MatchType ? MatchPattern { get ; set ; }
75
+
76
+ /// <inheritdoc />
33
77
public string Unmatch { get ; set ; }
34
78
79
+ /// <inheritdoc />
35
80
public string MatchMappingType { get ; set ; }
36
81
82
+ /// <inheritdoc />
37
83
public string PathMatch { get ; set ; }
38
84
85
+ /// <inheritdoc />
39
86
public string PathUnmatch { get ; set ; }
40
87
88
+ /// <inheritdoc />
41
89
public IProperty Mapping { get ; set ; }
42
90
}
43
91
92
+ /// <inheritdoc cref="IDynamicTemplate"/>
44
93
public class DynamicTemplateDescriptor < T > : DescriptorBase < DynamicTemplateDescriptor < T > , IDynamicTemplate > , IDynamicTemplate
45
94
where T : class
46
95
{
47
96
string IDynamicTemplate . Match { get ; set ; }
97
+ MatchType ? IDynamicTemplate . MatchPattern { get ; set ; }
48
98
string IDynamicTemplate . Unmatch { get ; set ; }
49
99
string IDynamicTemplate . MatchMappingType { get ; set ; }
50
100
string IDynamicTemplate . PathMatch { get ; set ; }
51
101
string IDynamicTemplate . PathUnmatch { get ; set ; }
52
102
IProperty IDynamicTemplate . Mapping { get ; set ; }
53
103
104
+ /// <inheritdoc cref="IDynamicTemplate.Match"/>
54
105
public DynamicTemplateDescriptor < T > Match ( string match ) => Assign ( a => a . Match = match ) ;
55
106
107
+ /// <inheritdoc cref="IDynamicTemplate.MatchPattern"/>
108
+ public DynamicTemplateDescriptor < T > MatchPattern ( MatchType ? matchPattern ) => Assign ( a => a . MatchPattern = matchPattern ) ;
109
+
110
+ /// <inheritdoc cref="IDynamicTemplate.Unmatch"/>
56
111
public DynamicTemplateDescriptor < T > Unmatch ( string unMatch ) => Assign ( a => a . Unmatch = unMatch ) ;
57
112
113
+ /// <inheritdoc cref="IDynamicTemplate.MatchMappingType"/>
58
114
public DynamicTemplateDescriptor < T > MatchMappingType ( string matchMappingType ) => Assign ( a => a . MatchMappingType = matchMappingType ) ;
59
115
116
+ /// <inheritdoc cref="IDynamicTemplate.PathMatch"/>
60
117
public DynamicTemplateDescriptor < T > PathMatch ( string pathMatch ) => Assign ( a => a . PathMatch = pathMatch ) ;
61
118
119
+ /// <inheritdoc cref="IDynamicTemplate.PathUnmatch"/>
62
120
public DynamicTemplateDescriptor < T > PathUnmatch ( string pathUnmatch ) => Assign ( a => a . PathUnmatch = pathUnmatch ) ;
63
121
122
+ /// <inheritdoc cref="IDynamicTemplate.Mapping"/>
64
123
public DynamicTemplateDescriptor < T > Mapping ( Func < SingleMappingSelector < T > , IProperty > mappingSelector ) => Assign ( a => a . Mapping = mappingSelector ? . Invoke ( new SingleMappingSelector < T > ( ) ) ) ;
65
124
}
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