diff --git a/src/Nest/Ingest/ProcessorFormatter.cs b/src/Nest/Ingest/ProcessorFormatter.cs index 98a26ca5b35..7cc498310f2 100644 --- a/src/Nest/Ingest/ProcessorFormatter.cs +++ b/src/Nest/Ingest/ProcessorFormatter.cs @@ -39,6 +39,7 @@ internal class ProcessorFormatter : IJsonFormatter { "set_security_user", 27 }, { "pipeline", 28 }, { "drop", 29 }, + { "circle", 30 }, }; public IProcessor Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver) @@ -149,6 +150,9 @@ public IProcessor Deserialize(ref JsonReader reader, IJsonFormatterResolver form case 29: processor = Deserialize(ref reader, formatterResolver); break; + case 30: + processor = Deserialize(ref reader, formatterResolver); + break; } } else @@ -260,6 +264,9 @@ public void Serialize(ref JsonWriter writer, IProcessor value, IJsonFormatterRes case "drop": Serialize(ref writer, value, formatterResolver); break; + case "circle": + Serialize(ref writer, value, formatterResolver); + break; default: var formatter = DynamicObjectResolver.ExcludeNullCamelCase.GetFormatter(); formatter.Serialize(ref writer, value, formatterResolver); diff --git a/src/Nest/Ingest/Processors/CircleProcessor.cs b/src/Nest/Ingest/Processors/CircleProcessor.cs new file mode 100644 index 00000000000..eacd0e6a3b5 --- /dev/null +++ b/src/Nest/Ingest/Processors/CircleProcessor.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Runtime.Serialization; +using Elasticsearch.Net; +using Elasticsearch.Net.Utf8Json; + +namespace Nest +{ + [StringEnum] + public enum ShapeType + { + [EnumMember(Value = "geo_shape")] + GeoShape, + + [EnumMember(Value = "shape")] + Shape + } + + [InterfaceDataContract] + public interface ICircleProcessor : IProcessor + { + /// + /// The string-valued field to trim whitespace from. + /// + [DataMember(Name ="field")] + Field Field { get; set; } + + /// + /// The field to assign the polygon shape to, by default field is updated in-place. + /// + [DataMember(Name ="target_field")] + Field TargetField { get; set; } + + /// + /// If true and field does not exist, the processor quietly exits without modifying the document. + /// + [DataMember(Name = "ignore_missing")] + bool? IgnoreMissing { get; set; } + + /// + /// The difference between the resulting inscribed distance from center to side and the circle’s radius + /// (measured in meters for geo_shape, unit-less for shape) + /// + [DataMember(Name = "error_distance")] + double? ErrorDistance { get; set; } + + /// + /// Which field mapping type is to be used when processing the circle. + /// + [DataMember(Name = "shape_type")] + ShapeType? ShapeType { get; set; } + } + + public class CircleProcessor : ProcessorBase, ICircleProcessor + { + /// + public Field Field { get; set; } + + /// + public Field TargetField { get; set; } + + /// + public bool? IgnoreMissing { get; set; } + + /// + public double? ErrorDistance { get; set; } + + /// + public ShapeType? ShapeType { get; set; } + + /// + protected override string Name => "circle"; + } + + public class CircleProcessorDescriptor + : ProcessorDescriptorBase, ICircleProcessor>, ICircleProcessor + where T : class + { + protected override string Name => "circle"; + + Field ICircleProcessor.Field { get; set; } + Field ICircleProcessor.TargetField { get; set; } + bool? ICircleProcessor.IgnoreMissing { get; set; } + double? ICircleProcessor.ErrorDistance { get; set; } + ShapeType? ICircleProcessor.ShapeType { get; set; } + + /// + public CircleProcessorDescriptor Field(Field field) => Assign(field, (a, v) => a.Field = v); + + /// + public CircleProcessorDescriptor Field(Expression> objectPath) => + Assign(objectPath, (a, v) => a.Field = v); + + /// + public CircleProcessorDescriptor TargetField(Field field) => Assign(field, (a, v) => a.TargetField = v); + + /// + public CircleProcessorDescriptor TargetField(Expression> objectPath) => + Assign(objectPath, (a, v) => a.TargetField = v); + + /// + public CircleProcessorDescriptor IgnoreMissing(bool? ignoreMissing = true) => + Assign(ignoreMissing, (a, v) => a.IgnoreMissing = v); + + /// + public CircleProcessorDescriptor ErrorDistance(double? errorDistance) => + Assign(errorDistance, (a, v) => a.ErrorDistance = v); + + /// + public CircleProcessorDescriptor ShapeType(ShapeType? shapeType) => + Assign(shapeType, (a, v) => a.ShapeType = v); + } +} diff --git a/src/Nest/Ingest/Processors/DissectProcessor.cs b/src/Nest/Ingest/Processors/DissectProcessor.cs index 974ab870dd7..6ff57f59e41 100644 --- a/src/Nest/Ingest/Processors/DissectProcessor.cs +++ b/src/Nest/Ingest/Processors/DissectProcessor.cs @@ -73,6 +73,7 @@ public DissectProcessorDescriptor Field(Expression> o public DissectProcessorDescriptor Pattern(string pattern) => Assign(pattern, (a, v) => a.Pattern = v); + // TODO! rename the parameter in 8.0 /// public DissectProcessorDescriptor IgnoreMissing(bool? traceMatch = true) => Assign(traceMatch, (a, v) => a.IgnoreMissing = v); diff --git a/src/Nest/Ingest/ProcessorsDescriptor.cs b/src/Nest/Ingest/ProcessorsDescriptor.cs index 7fa587c9d9b..d0ba1098eb7 100644 --- a/src/Nest/Ingest/ProcessorsDescriptor.cs +++ b/src/Nest/Ingest/ProcessorsDescriptor.cs @@ -154,5 +154,8 @@ public ProcessorsDescriptor SetSecurityUser(Func selector) => Assign(selector, (a, v) => a.AddIfNotNull(v?.Invoke(new PipelineProcessorDescriptor()))); + /// + public ProcessorsDescriptor Circle(Func, ICircleProcessor> selector) where T : class => + Assign(selector, (a, v) => a.AddIfNotNull(v?.Invoke(new CircleProcessorDescriptor()))); } } diff --git a/src/Tests/Tests/Ingest/ProcessorAssertions.cs b/src/Tests/Tests/Ingest/ProcessorAssertions.cs index 69396f5cd89..8039fa3729b 100644 --- a/src/Tests/Tests/Ingest/ProcessorAssertions.cs +++ b/src/Tests/Tests/Ingest/ProcessorAssertions.cs @@ -386,6 +386,38 @@ public class Attachment : ProcessorAssertion public override string Key => "attachment"; } + [SkipVersion("<7.4.0", "Circle processor added in 7.4.0")] + public class Circle : ProcessorAssertion + { + public override Func>> Fluent => d => d + .Circle(ud => ud + .Field(p => p.Description) + .TargetField(p => p.ArbitraryShape) + .ShapeType(ShapeType.Shape) + .ErrorDistance(10d) + .IgnoreMissing() + ); + + public override IProcessor Initializer => new CircleProcessor + { + Field = "description", + TargetField = "arbitraryShape", + ShapeType = ShapeType.Shape, + ErrorDistance = 10d, + IgnoreMissing = true + }; + + public override object Json => new + { + field = "description", + target_field = "arbitraryShape", + shape_type = "shape", + error_distance = 10.0, + ignore_missing = true, + }; + + public override string Key => "circle"; + } [SkipVersion("<6.4.0", "")] public class Bytes : ProcessorAssertion