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/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/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
{
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
}
}
};