1
1
using System ;
2
- using System . Collections ;
3
2
using System . Collections . Generic ;
4
- using System . Linq ;
5
3
using System . Linq . Expressions ;
6
4
using Newtonsoft . Json ;
7
5
@@ -11,33 +9,23 @@ namespace Nest
11
9
[ JsonConverter ( typeof ( ProcessorJsonConverter < KeyValueProcessor > ) ) ]
12
10
public interface IKeyValueProcessor : IProcessor
13
11
{
14
- /// <summary>
15
- /// The field to be parsed
16
- /// </summary>
12
+ /// <summary> The field to be parsed </summary>
17
13
[ JsonProperty ( "field" ) ]
18
14
Field Field { get ; set ; }
19
15
20
- /// <summary>
21
- /// The field to insert the extracted keys into. Defaults to the root of the document
22
- /// </summary>
16
+ /// <summary> The field to insert the extracted keys into. Defaults to the root of the document </summary>
23
17
[ JsonProperty ( "target_field" ) ]
24
18
Field TargetField { get ; set ; }
25
19
26
- /// <summary>
27
- /// Regex pattern to use for splitting key-value pairs
28
- /// </summary>
20
+ /// <summary> Regex pattern to use for splitting key-value pairs </summary>
29
21
[ JsonProperty ( "field_split" ) ]
30
22
string FieldSplit { get ; set ; }
31
23
32
- /// <summary>
33
- /// Regex pattern to use for splitting the key from the value within a key-value pair
34
- /// </summary>
24
+ /// <summary> Regex pattern to use for splitting the key from the value within a key-value pair </summary>
35
25
[ JsonProperty ( "value_split" ) ]
36
26
string ValueSplit { get ; set ; }
37
27
38
- /// <summary>
39
- /// List of keys to filter and insert into document. Defaults to including all keys
40
- /// </summary>
28
+ /// <summary> List of keys to filter and insert into document. Defaults to including all keys </summary>
41
29
[ JsonProperty ( "include_keys" ) ]
42
30
IEnumerable < string > IncludeKeys { get ; set ; }
43
31
@@ -46,8 +34,21 @@ public interface IKeyValueProcessor : IProcessor
46
34
/// </summary>
47
35
[ JsonProperty ( "ignore_missing" ) ]
48
36
bool ? IgnoreMissing { get ; set ; }
37
+
38
+ /// <summary> String of characters to trim from extracted keys </summary>
39
+ [ JsonProperty ( "trim_key" ) ]
40
+ string TrimKey { get ; set ; }
41
+
42
+ /// <summary> String of characters to trim from extracted values </summary>
43
+ [ JsonProperty ( "trim_value" ) ]
44
+ string TrimValue { get ; set ; }
45
+
46
+ /// <summary> If true strip brackets (), <>, [] as well as quotes ' and " from extracted values </summary>
47
+ [ JsonProperty ( "strip_brackets" ) ]
48
+ bool ? StripBrackets { get ; set ; }
49
49
}
50
50
51
+ /// <inheritdoc cref="IKeyValueProcessor"/>
51
52
public class KeyValueProcessor : ProcessorBase , IKeyValueProcessor
52
53
{
53
54
protected override string Name => "kv" ;
@@ -69,8 +70,18 @@ public class KeyValueProcessor : ProcessorBase, IKeyValueProcessor
69
70
70
71
/// <inheritdoc/>
71
72
public bool ? IgnoreMissing { get ; set ; }
73
+
74
+ /// <inheritdoc/>
75
+ public string TrimKey { get ; set ; }
76
+
77
+ /// <inheritdoc/>
78
+ public string TrimValue { get ; set ; }
79
+
80
+ /// <inheritdoc/>
81
+ public bool ? StripBrackets { get ; set ; }
72
82
}
73
83
84
+ /// <inheritdoc cref="IKeyValueProcessor"/>
74
85
public class KeyValueProcessorDescriptor < T > : ProcessorDescriptorBase < KeyValueProcessorDescriptor < T > , IKeyValueProcessor > , IKeyValueProcessor
75
86
where T : class
76
87
{
@@ -82,33 +93,45 @@ public class KeyValueProcessorDescriptor<T> : ProcessorDescriptorBase<KeyValuePr
82
93
string IKeyValueProcessor . ValueSplit { get ; set ; }
83
94
IEnumerable < string > IKeyValueProcessor . IncludeKeys { get ; set ; }
84
95
bool ? IKeyValueProcessor . IgnoreMissing { get ; set ; }
96
+ string IKeyValueProcessor . TrimKey { get ; set ; }
97
+ string IKeyValueProcessor . TrimValue { get ; set ; }
98
+ bool ? IKeyValueProcessor . StripBrackets { get ; set ; }
85
99
86
- /// <inheritdoc/>
100
+ /// <inheritdoc cref="IKeyValueProcessor.Field" />
87
101
public KeyValueProcessorDescriptor < T > Field ( Field field ) => Assign ( a => a . Field = field ) ;
88
102
89
- /// <inheritdoc/>
103
+ /// <inheritdoc cref="IKeyValueProcessor.Field" />
90
104
public KeyValueProcessorDescriptor < T > Field ( Expression < Func < T , object > > objectPath ) => Assign ( a => a . Field = objectPath ) ;
91
105
92
- /// <inheritdoc/>
106
+ /// <inheritdoc cref="IKeyValueProcessor.TargetField" />
93
107
public KeyValueProcessorDescriptor < T > TargetField ( Field field ) => Assign ( a => a . TargetField = field ) ;
94
108
95
- /// <inheritdoc/>
109
+ /// <inheritdoc cref="IKeyValueProcessor.TargetField" />
96
110
public KeyValueProcessorDescriptor < T > TargetField ( Expression < Func < T , object > > objectPath ) => Assign ( a => a . TargetField = objectPath ) ;
97
111
98
- /// <inheritdoc/>
112
+ /// <inheritdoc cref="IKeyValueProcessor.FieldSplit" />
99
113
public KeyValueProcessorDescriptor < T > FieldSplit ( string split ) => Assign ( a => a . FieldSplit = split ) ;
100
114
101
- /// <inheritdoc/>
115
+ /// <inheritdoc cref="IKeyValueProcessor.ValueSplit" />
102
116
public KeyValueProcessorDescriptor < T > ValueSplit ( string split ) => Assign ( a => a . ValueSplit = split ) ;
103
117
104
- /// <inheritdoc/>
118
+ /// <inheritdoc cref="IKeyValueProcessor.IgnoreMissing" />
105
119
public KeyValueProcessorDescriptor < T > IgnoreMissing ( bool ? ignoreMissing = true ) => Assign ( a => a . IgnoreMissing = ignoreMissing ) ;
106
120
107
- /// <inheritdoc/>
121
+ /// <inheritdoc cref="IKeyValueProcessor.IncludeKeys" />
108
122
public KeyValueProcessorDescriptor < T > IncludeKeys ( IEnumerable < string > includeKeys ) => Assign ( a => a . IncludeKeys = includeKeys ) ;
109
123
110
- /// <inheritdoc/>
124
+ /// <inheritdoc cref="IKeyValueProcessor.IncludeKeys" />
111
125
public KeyValueProcessorDescriptor < T > IncludeKeys ( params string [ ] includeKeys ) => Assign ( a => a . IncludeKeys = includeKeys ) ;
126
+
127
+ /// <inheritdoc cref="IKeyValueProcessor.TrimKey"/>
128
+ public KeyValueProcessorDescriptor < T > TrimKey ( string trimKeys ) => Assign ( a => a . TrimKey = trimKeys ) ;
129
+
130
+ /// <inheritdoc cref="IKeyValueProcessor.TrimValue"/>
131
+ public KeyValueProcessorDescriptor < T > TrimValue ( string trimValues ) => Assign ( a => a . TrimValue = trimValues ) ;
132
+
133
+ /// <inheritdoc cref="IKeyValueProcessor.StripBrackets"/>
134
+ public KeyValueProcessorDescriptor < T > StripBrackets ( bool ? skip = true ) => Assign ( a => a . StripBrackets = skip ) ;
112
135
}
113
136
114
137
}
0 commit comments