Skip to content

Commit 4839693

Browse files
authored
Add ignore_missing to ingest processors (#3623)
This commit adds missing fields for ingest processors, including ignore_missing and target_field Fixes #3619
1 parent 973c666 commit 4839693

24 files changed

+590
-76
lines changed

src/Nest/Analysis/Plugins/Icu/IcuAnalyzer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public class IcuAnalyzerDescriptor : AnalyzerDescriptorBase<IcuAnalyzerDescripto
4646
IcuNormalizationMode? IIcuAnalyzer.Mode { get; set; }
4747

4848
/// <inheritdoc cref="IIcuAnalyzer.Method"/>
49-
public IcuAnalyzerDescriptor Method(IcuNormalizationType? method) => Assign(a => a.Method = method);
49+
public IcuAnalyzerDescriptor Method(IcuNormalizationType? method) => Assign(method, (a, v) => a.Method = v);
5050

5151
/// <inheritdoc cref="IIcuAnalyzer.Mode"/>
52-
public IcuAnalyzerDescriptor Mode(IcuNormalizationMode? mode) => Assign(a => a.Mode = mode);
52+
public IcuAnalyzerDescriptor Mode(IcuNormalizationMode? mode) => Assign(mode, (a, v) => a.Mode = v);
5353
}
5454
}

src/Nest/Ingest/Processors/ConvertProcessor.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,52 @@
66

77
namespace Nest
88
{
9+
/// <summary>
10+
/// Converts a field in the currently ingested document to a different type,
11+
/// such as converting a string to an integer.
12+
/// If the field value is an array, all members will be converted.
13+
/// </summary>
914
[JsonObject(MemberSerialization.OptIn)]
1015
[JsonConverter(typeof(ProcessorJsonConverter<ConvertProcessor>))]
1116
public interface IConvertProcessor : IProcessor
1217
{
18+
/// <summary>
19+
/// The field whose value is to be converted
20+
/// </summary>
1321
[JsonProperty("field")]
1422
Field Field { get; set; }
1523

24+
/// <summary>
25+
/// The field to assign the converted value to, by default field is updated in-place
26+
/// </summary>
1627
[JsonProperty("target_field")]
1728
Field TargetField { get; set; }
1829

30+
/// <summary>
31+
/// The type to convert the existing value to
32+
/// </summary>
1933
[JsonProperty("type")]
2034
ConvertProcessorType? Type { get; set; }
35+
36+
/// <summary>
37+
/// If <c>true</c> and <see cref="Field" /> does not exist or is null,
38+
/// the processor quietly exits without modifying the document. Default is <c>false</c>
39+
/// </summary>
40+
[JsonProperty("ignore_missing")]
41+
bool? IgnoreMissing { get; set; }
2142
}
2243

2344
public class ConvertProcessor : ProcessorBase, IConvertProcessor
2445
{
46+
/// <inheritdoc />
2547
public Field Field { get; set; }
48+
/// <inheritdoc />
2649
public Field TargetField { get; set; }
50+
/// <inheritdoc />
2751
public ConvertProcessorType? Type { get; set; }
52+
/// <inheritdoc />
53+
public bool? IgnoreMissing { get; set; }
54+
/// <inheritdoc />
2855
protected override string Name => "convert";
2956
}
3057

@@ -34,19 +61,28 @@ public class ConvertProcessorDescriptor<T> : ProcessorDescriptorBase<ConvertProc
3461
protected override string Name => "convert";
3562
Field IConvertProcessor.Field { get; set; }
3663
Field IConvertProcessor.TargetField { get; set; }
64+
bool? IConvertProcessor.IgnoreMissing { get; set; }
3765
ConvertProcessorType? IConvertProcessor.Type { get; set; }
3866

67+
/// <inheritdoc cref="IConvertProcessor.Field" />
3968
public ConvertProcessorDescriptor<T> Field(Field field) => Assign(field, (a, v) => a.Field = v);
4069

70+
/// <inheritdoc cref="IConvertProcessor.Field" />
4171
public ConvertProcessorDescriptor<T> Field(Expression<Func<T, object>> objectPath) =>
4272
Assign(objectPath, (a, v) => a.Field = v);
4373

74+
/// <inheritdoc cref="IConvertProcessor.TargetField" />
4475
public ConvertProcessorDescriptor<T> TargetField(Field field) => Assign(field, (a, v) => a.TargetField = v);
4576

77+
/// <inheritdoc cref="IConvertProcessor.TargetField" />
4678
public ConvertProcessorDescriptor<T> TargetField(Expression<Func<T, object>> objectPath) =>
4779
Assign(objectPath, (a, v) => a.TargetField = v);
4880

81+
/// <inheritdoc cref="IConvertProcessor.Type" />
4982
public ConvertProcessorDescriptor<T> Type(ConvertProcessorType? type) => Assign(type, (a, v) => a.Type = v);
83+
84+
/// <inheritdoc cref="IConvertProcessor.IgnoreMissing" />
85+
public ConvertProcessorDescriptor<T> IgnoreMissing(bool? ignoreMissing = true) => Assign(ignoreMissing, (a, v) => a.IgnoreMissing = v);
5086
}
5187

5288
[JsonConverter(typeof(StringEnumConverter))]
@@ -55,9 +91,15 @@ public enum ConvertProcessorType
5591
[EnumMember(Value = "integer")]
5692
Integer,
5793

94+
[EnumMember(Value = "long")]
95+
Long,
96+
5897
[EnumMember(Value = "float")]
5998
Float,
6099

100+
[EnumMember(Value = "double")]
101+
Double,
102+
61103
[EnumMember(Value = "string")]
62104
String,
63105

src/Nest/Ingest/Processors/DateProcessor.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,57 @@ namespace Nest
99
[JsonConverter(typeof(ProcessorJsonConverter<DateProcessor>))]
1010
public interface IDateProcessor : IProcessor
1111
{
12+
/// <summary>
13+
/// The field to get the date from.
14+
/// </summary>
1215
[JsonProperty("field")]
1316
Field Field { get; set; }
1417

18+
/// <summary>
19+
/// An array of the expected date formats. Can be a Joda pattern or one of
20+
/// the following formats: ISO8601, UNIX, UNIX_MS, or TAI64N.
21+
/// </summary>
1522
[JsonProperty("formats")]
1623
IEnumerable<string> Formats { get; set; }
1724

25+
/// <summary>
26+
/// The locale to use when parsing the date, relevant when parsing month names or week days.
27+
/// Supports template snippets.
28+
/// </summary>
1829
[JsonProperty("locale")]
1930
string Locale { get; set; }
2031

32+
/// <summary>
33+
/// The field that will hold the parsed date. Defaults to @timestamp
34+
/// </summary>
2135
[JsonProperty("target_field")]
2236
Field TargetField { get; set; }
2337

38+
/// <summary>
39+
/// The timezone to use when parsing the date. Supports template snippets.
40+
/// </summary>
2441
[JsonProperty("timezone")]
2542
string Timezone { get; set; }
2643
}
2744

2845
public class DateProcessor : ProcessorBase, IDateProcessor
2946
{
47+
/// <inheritdoc />
3048
public Field Field { get; set; }
3149

50+
/// <inheritdoc />
3251
public IEnumerable<string> Formats { get; set; }
3352

53+
/// <inheritdoc />
3454
public string Locale { get; set; }
3555

56+
/// <inheritdoc />
3657
public Field TargetField { get; set; }
3758

59+
/// <inheritdoc />
3860
public string Timezone { get; set; }
61+
62+
/// <inheritdoc />
3963
protected override string Name => "date";
4064
}
4165

@@ -51,22 +75,30 @@ public class DateProcessorDescriptor<T>
5175
Field IDateProcessor.TargetField { get; set; }
5276
string IDateProcessor.Timezone { get; set; }
5377

78+
/// <inheritdoc cref="IDateProcessor.Field" />
5479
public DateProcessorDescriptor<T> Field(Field field) => Assign(field, (a, v) => a.Field = v);
5580

81+
/// <inheritdoc cref="IDateProcessor.Field" />
5682
public DateProcessorDescriptor<T> Field(Expression<Func<T, object>> objectPath) =>
5783
Assign(objectPath, (a, v) => a.Field = v);
5884

85+
/// <inheritdoc cref="IDateProcessor.TargetField" />
5986
public DateProcessorDescriptor<T> TargetField(Field field) => Assign(field, (a, v) => a.TargetField = v);
6087

88+
/// <inheritdoc cref="IDateProcessor.TargetField" />
6189
public DateProcessorDescriptor<T> TargetField(Expression<Func<T, object>> objectPath) =>
6290
Assign(objectPath, (a, v) => a.TargetField = v);
6391

92+
/// <inheritdoc cref="IDateProcessor.Formats" />
6493
public DateProcessorDescriptor<T> Formats(IEnumerable<string> matchFormats) => Assign(matchFormats, (a, v) => a.Formats = v);
6594

95+
/// <inheritdoc cref="IDateProcessor.Formats" />
6696
public DateProcessorDescriptor<T> Formats(params string[] matchFormats) => Assign(matchFormats, (a, v) => a.Formats = v);
6797

98+
/// <inheritdoc cref="IDateProcessor.Timezone" />
6899
public DateProcessorDescriptor<T> Timezone(string timezone) => Assign(timezone, (a, v) => a.Timezone = v);
69100

101+
/// <inheritdoc cref="IDateProcessor.Locale" />
70102
public DateProcessorDescriptor<T> Locale(string locale) => Assign(locale, (a, v) => a.Locale = v);
71103
}
72104
}

src/Nest/Ingest/Processors/DissectProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public interface IDissectProcessor : IProcessor
2222
[JsonProperty("pattern")]
2323
string Pattern { get; set; }
2424

25-
/// <summary
26-
/// If true and field does not exist or is null, the processor quietly exits without modifying the document>
25+
/// <summary>
26+
/// If <c>true</c> and field does not exist or is null, the processor quietly exits without modifying the document
2727
/// </summary>
2828
[JsonProperty("ignore_missing")]
2929
bool? IgnoreMissing { get; set; }

src/Nest/Ingest/Processors/DotExpanderProcessor.cs

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,21 @@ public interface IDotExpanderProcessor : IProcessor
2828
string Path { get; set; }
2929
}
3030

31-
/// <summary>
32-
/// Expands a field with dots into an object field.
33-
/// This processor allows fields with dots in the name to be accessible by other processors in the pipeline.
34-
/// Otherwise these fields can’t be accessed by any processor.
35-
/// </summary>
31+
/// <inheritdoc cref="IDotExpanderProcessor" />
3632
public class DotExpanderProcessor : ProcessorBase, IDotExpanderProcessor
3733
{
38-
/// <summary>
39-
/// The field to expand into an object field
40-
/// </summary>
34+
/// <inheritdoc />
4135
[JsonProperty("field")]
4236
public Field Field { get; set; }
4337

44-
/// <summary>
45-
/// The field that contains the field to expand.
46-
/// Only required if the field to expand is part another object field,
47-
/// because the field option can only understand leaf fields.
48-
/// </summary>
38+
/// <inheritdoc />
4939
[JsonProperty("path")]
5040
public string Path { get; set; }
5141

5242
protected override string Name => "dot_expander";
5343
}
5444

55-
/// <summary>
56-
/// Expands a field with dots into an object field.
57-
/// This processor allows fields with dots in the name to be accessible by other processors in the pipeline.
58-
/// Otherwise these fields can’t be accessed by any processor.
59-
/// </summary>
45+
/// <inheritdoc cref="IDotExpanderProcessor" />
6046
public class DotExpanderProcessorDescriptor<T>
6147
: ProcessorDescriptorBase<DotExpanderProcessorDescriptor<T>, IDotExpanderProcessor>, IDotExpanderProcessor
6248
where T : class
@@ -66,22 +52,14 @@ public class DotExpanderProcessorDescriptor<T>
6652
Field IDotExpanderProcessor.Field { get; set; }
6753
string IDotExpanderProcessor.Path { get; set; }
6854

69-
/// <summary>
70-
/// The field to expand into an object field
71-
/// </summary>
55+
/// <inheritdoc cref="IDotExpanderProcessor.Field" />
7256
public DotExpanderProcessorDescriptor<T> Field(Field field) => Assign(field, (a, v) => a.Field = v);
7357

74-
/// <summary>
75-
/// The field to expand into an object field
76-
/// </summary>
58+
/// <inheritdoc cref="IDotExpanderProcessor.Field" />
7759
public DotExpanderProcessorDescriptor<T> Field(Expression<Func<T, object>> objectPath) =>
7860
Assign(objectPath, (a, v) => a.Field = v);
7961

80-
/// <summary>
81-
/// The field that contains the field to expand.
82-
/// Only required if the field to expand is part another object field,
83-
/// because the field option can only understand leaf fields.
84-
/// </summary>
62+
/// <inheritdoc cref="IDotExpanderProcessor.Path" />
8563
public DotExpanderProcessorDescriptor<T> Path(string path) => Assign(path, (a, v) => a.Path = v);
8664
}
8765
}

src/Nest/Ingest/Processors/FailProcessor.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,38 @@
22

33
namespace Nest
44
{
5+
/// <summary>
6+
/// Raises an exception. This is useful for when you expect a pipeline to
7+
/// fail and want to relay a specific message to the requester.
8+
/// </summary>
59
[JsonObject(MemberSerialization.OptIn)]
610
[JsonConverter(typeof(ProcessorJsonConverter<FailProcessor>))]
711
public interface IFailProcessor : IProcessor
812
{
13+
/// <summary>
14+
/// The error message thrown by the processor. Supports template snippets.
15+
/// </summary>
916
[JsonProperty("message")]
1017
string Message { get; set; }
1118
}
1219

20+
/// <inheritdoc cref="IFailProcessor" />
1321
public class FailProcessor : ProcessorBase, IFailProcessor
1422
{
23+
/// <inheritdoc />
1524
public string Message { get; set; }
1625
protected override string Name => "fail";
1726
}
1827

28+
/// <inheritdoc cref="IFailProcessor" />
1929
public class FailProcessorDescriptor
2030
: ProcessorDescriptorBase<FailProcessorDescriptor, IFailProcessor>, IFailProcessor
2131
{
2232
protected override string Name => "fail";
2333

2434
string IFailProcessor.Message { get; set; }
2535

36+
/// <inheritdoc cref="IFailProcessor.Message" />
2637
public FailProcessorDescriptor Message(string message) => Assign(message, (a, v) => a.Message = v);
2738
}
2839
}

src/Nest/Ingest/Processors/ForeachProcessor.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,74 @@
66

77
namespace Nest
88
{
9+
/// <summary>
10+
/// Processes elements in an array of unknown length.
11+
/// All processors can operate on elements inside an array, but if all elements of
12+
/// an array need to be processed in the same way, defining a processor for each
13+
/// element becomes cumbersome and tricky because it is likely that the number of
14+
/// elements in an array is unknown. For this reason the foreach processor exists.
15+
/// By specifying the field holding array elements and a processor that defines what
16+
/// should happen to each element, array fields can easily be preprocessed.
17+
/// </summary>
918
[JsonObject(MemberSerialization.OptIn)]
1019
[JsonConverter(typeof(ProcessorJsonConverter<ForeachProcessor>))]
1120
public interface IForeachProcessor : IProcessor
1221
{
22+
/// <summary>
23+
/// The array field
24+
/// </summary>
1325
[JsonProperty("field")]
1426
Field Field { get; set; }
1527

28+
/// <summary>
29+
/// The processor to execute against each field
30+
/// </summary>
1631
[JsonProperty("processor")]
1732
IProcessor Processor { get; set; }
33+
34+
/// <summary>
35+
/// If <c>true</c> and <see cref="Field" /> does not exist or is null,
36+
/// the processor quietly exits without modifying the document. Default is <c>false</c>
37+
/// </summary>
38+
[JsonProperty("ignore_missing")]
39+
bool? IgnoreMissing { get; set; }
1840
}
1941

42+
/// <inheritdoc cref="IForeachProcessor"/>
2043
public class ForeachProcessor : ProcessorBase, IForeachProcessor
2144
{
45+
/// <inheritdoc />
2246
public Field Field { get; set; }
47+
/// <inheritdoc />
2348
public IProcessor Processor { get; set; }
49+
/// <inheritdoc />
50+
public bool? IgnoreMissing { get; set; }
2451
protected override string Name => "foreach";
2552
}
2653

54+
/// <inheritdoc cref="IForeachProcessor"/>
2755
public class ForeachProcessorDescriptor<T>
2856
: ProcessorDescriptorBase<ForeachProcessorDescriptor<T>, IForeachProcessor>, IForeachProcessor
2957
where T : class
3058
{
3159
protected override string Name => "foreach";
3260

3361
Field IForeachProcessor.Field { get; set; }
34-
3562
IProcessor IForeachProcessor.Processor { get; set; }
63+
bool? IForeachProcessor.IgnoreMissing { get; set; }
3664

65+
/// <inheritdoc cref="IForeachProcessor.Field"/>
3766
public ForeachProcessorDescriptor<T> Field(Field field) => Assign(field, (a, v) => a.Field = v);
3867

68+
/// <inheritdoc cref="IForeachProcessor.Field"/>
3969
public ForeachProcessorDescriptor<T> Field(Expression<Func<T, object>> objectPath) =>
4070
Assign(objectPath, (a, v) => a.Field = v);
4171

72+
/// <inheritdoc cref="IForeachProcessor.Processor"/>
4273
public ForeachProcessorDescriptor<T> Processor(Func<ProcessorsDescriptor, IPromise<IList<IProcessor>>> selector) =>
4374
Assign(selector, (a, v) => a.Processor = v?.Invoke(new ProcessorsDescriptor())?.Value?.FirstOrDefault());
75+
76+
/// <inheritdoc cref="IForeachProcessor.IgnoreMissing" />
77+
public ForeachProcessorDescriptor<T> IgnoreMissing(bool? ignoreMissing = true) => Assign(ignoreMissing, (a, v) => a.IgnoreMissing = v);
4478
}
4579
}

0 commit comments

Comments
 (0)