From 72b9472081ceff52f3f6bcde271c6fdb94abd865 Mon Sep 17 00:00:00 2001 From: Stuart Cam Date: Mon, 6 May 2019 19:15:21 +1000 Subject: [PATCH 1/2] Allow geo_shape types to be coerced into valid shapes. Relates to https://github.com/elastic/elasticsearch/issues/35059 --- .../Types/Geo/GeoShape/GeoShapeProperty.cs | 15 +++++++++++++++ .../Types/Geo/GeoShape/GeoShapePropertyTests.cs | 7 +++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Nest/Mapping/Types/Geo/GeoShape/GeoShapeProperty.cs b/src/Nest/Mapping/Types/Geo/GeoShape/GeoShapeProperty.cs index 052cf35b201..9170ce6dbb3 100644 --- a/src/Nest/Mapping/Types/Geo/GeoShape/GeoShapeProperty.cs +++ b/src/Nest/Mapping/Types/Geo/GeoShape/GeoShapeProperty.cs @@ -97,6 +97,12 @@ public interface IGeoShapeProperty : IDocValuesProperty /// [JsonProperty("tree_levels")] int? TreeLevels { get; set; } + + /// + /// Should the data be coerced into becoming a valid geo shape (for instance closing a polygon) + /// + [JsonProperty("coerce")] + bool? Coerce { get; set; } } /// @@ -131,6 +137,9 @@ public GeoShapeProperty() : base(FieldType.GeoShape) { } /// public int? TreeLevels { get; set; } + + /// + public bool? Coerce { get; set; } } /// @@ -151,6 +160,8 @@ public GeoShapePropertyDescriptor() : base(FieldType.GeoShape) { } GeoTree? IGeoShapeProperty.Tree { get; set; } int? IGeoShapeProperty.TreeLevels { get; set; } + bool? IGeoShapeProperty.Coerce { get; set; } + /// public GeoShapePropertyDescriptor Tree(GeoTree? tree) => Assign(tree, (a, v) => a.Tree = v); @@ -181,5 +192,9 @@ public GeoShapePropertyDescriptor IgnoreMalformed(bool? ignoreMalformed = tru /// public GeoShapePropertyDescriptor IgnoreZValue(bool? ignoreZValue = true) => Assign(ignoreZValue, (a, v) => a.IgnoreZValue = v); + + /// + public GeoShapePropertyDescriptor Coerce(bool? coerce = true) => + Assign(coerce, (a, v) => a.Coerce = v); } } diff --git a/src/Tests/Tests/Mapping/Types/Geo/GeoShape/GeoShapePropertyTests.cs b/src/Tests/Tests/Mapping/Types/Geo/GeoShape/GeoShapePropertyTests.cs index ab7c903a85d..2e9656629dd 100644 --- a/src/Tests/Tests/Mapping/Types/Geo/GeoShape/GeoShapePropertyTests.cs +++ b/src/Tests/Tests/Mapping/Types/Geo/GeoShape/GeoShapePropertyTests.cs @@ -22,7 +22,8 @@ public GeoShapePropertyTests(WritableCluster cluster, EndpointUsage usage) : bas strategy = "recursive", tree_levels = 3, points_only = true, - distance_error_pct = 1.0 + distance_error_pct = 1.0, + coerce = true } } }; @@ -36,6 +37,7 @@ public GeoShapePropertyTests(WritableCluster cluster, EndpointUsage usage) : bas .TreeLevels(3) .PointsOnly() .DistanceErrorPercentage(1.0) + .Coerce() ); @@ -49,7 +51,8 @@ public GeoShapePropertyTests(WritableCluster cluster, EndpointUsage usage) : bas Strategy = GeoStrategy.Recursive, TreeLevels = 3, PointsOnly = true, - DistanceErrorPercentage = 1.0 + DistanceErrorPercentage = 1.0, + Coerce = true } } }; From 4b3fb24a63d20f79b83867e3c5ae26d90d3f60b3 Mon Sep 17 00:00:00 2001 From: Stuart Cam Date: Mon, 6 May 2019 19:23:02 +1000 Subject: [PATCH 2/2] Add Coerce to attricute --- src/Nest/Mapping/Types/Geo/GeoShape/GeoShapeAttribute.cs | 9 +++++++++ .../Mapping/Types/Geo/GeoShape/GeoShapeAttributeTests.cs | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Nest/Mapping/Types/Geo/GeoShape/GeoShapeAttribute.cs b/src/Nest/Mapping/Types/Geo/GeoShape/GeoShapeAttribute.cs index f4e555a1abd..675d5ce0134 100644 --- a/src/Nest/Mapping/Types/Geo/GeoShape/GeoShapeAttribute.cs +++ b/src/Nest/Mapping/Types/Geo/GeoShape/GeoShapeAttribute.cs @@ -63,6 +63,13 @@ public int TreeLevels set => Self.TreeLevels = value; } + /// + public bool Coerce + { + get => Self.Coerce.GetValueOrDefault(true); + set => Self.Coerce = value; + } + double? IGeoShapeProperty.DistanceErrorPercentage { get; set; } bool? IGeoShapeProperty.IgnoreMalformed { get; set; } bool? IGeoShapeProperty.IgnoreZValue { get; set; } @@ -74,5 +81,7 @@ public int TreeLevels GeoTree? IGeoShapeProperty.Tree { get; set; } int? IGeoShapeProperty.TreeLevels { get; set; } + + bool? IGeoShapeProperty.Coerce { get; set; } } } diff --git a/src/Tests/Tests/Mapping/Types/Geo/GeoShape/GeoShapeAttributeTests.cs b/src/Tests/Tests/Mapping/Types/Geo/GeoShape/GeoShapeAttributeTests.cs index e60c4ecc96b..26ab0b55438 100644 --- a/src/Tests/Tests/Mapping/Types/Geo/GeoShape/GeoShapeAttributeTests.cs +++ b/src/Tests/Tests/Mapping/Types/Geo/GeoShape/GeoShapeAttributeTests.cs @@ -10,7 +10,8 @@ public class GeoShapeTest Strategy = GeoStrategy.Recursive, TreeLevels = 3, PointsOnly = true, - DistanceErrorPercentage = 1.0)] + DistanceErrorPercentage = 1.0, + Coerce = true)] public object Full { get; set; } [GeoShape] @@ -31,7 +32,8 @@ public class GeoShapeAttributeTests : AttributeTestsBase strategy = "recursive", tree_levels = 3, points_only = true, - distance_error_pct = 1.0 + distance_error_pct = 1.0, + coerce = true }, minimal = new {