Skip to content

Commit 6e466d4

Browse files
committed
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 6965cf4 commit 6e466d4

24 files changed

+573
-66
lines changed

src/Nest/Ingest/Processors/ConvertProcessor.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,51 @@
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
[InterfaceDataContract]
1015
public interface IConvertProcessor : IProcessor
1116
{
17+
/// <summary>
18+
/// The field whose value is to be converted
19+
/// </summary>
1220
[DataMember(Name ="field")]
1321
Field Field { get; set; }
1422

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

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

2243
public class ConvertProcessor : ProcessorBase, IConvertProcessor
2344
{
45+
/// <inheritdoc />
2446
public Field Field { get; set; }
47+
/// <inheritdoc />
2548
public Field TargetField { get; set; }
49+
/// <inheritdoc />
2650
public ConvertProcessorType? Type { get; set; }
51+
/// <inheritdoc />
52+
public bool? IgnoreMissing { get; set; }
53+
/// <inheritdoc />
2754
protected override string Name => "convert";
2855
}
2956

@@ -33,19 +60,28 @@ public class ConvertProcessorDescriptor<T> : ProcessorDescriptorBase<ConvertProc
3360
protected override string Name => "convert";
3461
Field IConvertProcessor.Field { get; set; }
3562
Field IConvertProcessor.TargetField { get; set; }
63+
bool? IConvertProcessor.IgnoreMissing { get; set; }
3664
ConvertProcessorType? IConvertProcessor.Type { get; set; }
3765

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

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

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

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

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

5187
[StringEnum]
@@ -54,9 +90,15 @@ public enum ConvertProcessorType
5490
[EnumMember(Value = "integer")]
5591
Integer,
5692

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

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

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
[InterfaceDataContract]
1010
public interface IDateProcessor : IProcessor
1111
{
12+
/// <summary>
13+
/// The field to get the date from.
14+
/// </summary>
1215
[DataMember(Name ="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
[DataMember(Name ="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
[DataMember(Name ="locale")]
1930
string Locale { get; set; }
2031

32+
/// <summary>
33+
/// The field that will hold the parsed date. Defaults to @timestamp
34+
/// </summary>
2135
[DataMember(Name ="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
[DataMember(Name ="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<TValue>(Expression<Func<T, TValue>> 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<TValue>(Expression<Func<T, TValue>> 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
[DataMember(Name = "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
[DataMember(Name = "ignore_missing")]
2929
bool? IgnoreMissing { get; set; }

src/Nest/Ingest/Processors/DotExpanderProcessor.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ 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
{
3834
/// <summary>
@@ -52,11 +48,7 @@ public class DotExpanderProcessor : ProcessorBase, IDotExpanderProcessor
5248
protected override string Name => "dot_expander";
5349
}
5450

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>
51+
/// <inheritdoc cref="IDotExpanderProcessor" />
6052
public class DotExpanderProcessorDescriptor<T>
6153
: ProcessorDescriptorBase<DotExpanderProcessorDescriptor<T>, IDotExpanderProcessor>, IDotExpanderProcessor
6254
where T : class
@@ -66,9 +58,7 @@ public class DotExpanderProcessorDescriptor<T>
6658
Field IDotExpanderProcessor.Field { get; set; }
6759
string IDotExpanderProcessor.Path { get; set; }
6860

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

7464
/// <summary>
@@ -77,11 +67,7 @@ public class DotExpanderProcessorDescriptor<T>
7767
public DotExpanderProcessorDescriptor<T> Field<TValue>(Expression<Func<T, TValue>> objectPath) =>
7868
Assign(objectPath, (a, v) => a.Field = v);
7969

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>
70+
/// <inheritdoc cref="IDotExpanderProcessor.Path" />
8571
public DotExpanderProcessorDescriptor<T> Path(string path) => Assign(path, (a, v) => a.Path = v);
8672
}
8773
}

src/Nest/Ingest/Processors/FailProcessor.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,37 @@
33

44
namespace Nest
55
{
6+
/// <summary>
7+
/// Raises an exception. This is useful for when you expect a pipeline to
8+
/// fail and want to relay a specific message to the requester.
9+
/// </summary>
610
[InterfaceDataContract]
711
public interface IFailProcessor : IProcessor
812
{
13+
/// <summary>
14+
/// The error message thrown by the processor. Supports template snippets.
15+
/// </summary>
916
[DataMember(Name ="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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,51 @@
77

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

28+
/// <summary>
29+
/// The processor to execute against each field
30+
/// </summary>
1631
[DataMember(Name ="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+
[DataMember(Name = "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
@@ -33,13 +61,20 @@ public class ForeachProcessorDescriptor<T>
3361
Field IForeachProcessor.Field { get; set; }
3462

3563
IProcessor IForeachProcessor.Processor { get; set; }
64+
bool? IForeachProcessor.IgnoreMissing { get; set; }
3665

66+
/// <inheritdoc cref="IForeachProcessor.Field"/>
3767
public ForeachProcessorDescriptor<T> Field(Field field) => Assign(field, (a, v) => a.Field = v);
3868

69+
/// <inheritdoc cref="IForeachProcessor.Field"/>
3970
public ForeachProcessorDescriptor<T> Field<TValue>(Expression<Func<T, TValue>> objectPath) =>
4071
Assign(objectPath, (a, v) => a.Field = v);
4172

73+
/// <inheritdoc cref="IForeachProcessor.Processor"/>
4274
public ForeachProcessorDescriptor<T> Processor(Func<ProcessorsDescriptor, IPromise<IList<IProcessor>>> selector) =>
4375
Assign(selector, (a, v) => a.Processor = v?.Invoke(new ProcessorsDescriptor())?.Value?.FirstOrDefault());
76+
77+
/// <inheritdoc cref="IForeachProcessor.IgnoreMissing" />
78+
public ForeachProcessorDescriptor<T> IgnoreMissing(bool? ignoreMissing = true) => Assign(ignoreMissing, (a, v) => a.IgnoreMissing = v);
4479
}
4580
}

0 commit comments

Comments
 (0)