diff --git a/src/Nest/QueryDsl/Geo/BoundingBox/GeoBoundingBoxQuery.cs b/src/Nest/QueryDsl/Geo/BoundingBox/GeoBoundingBoxQuery.cs index d1ec4976248..eee8d9b268f 100644 --- a/src/Nest/QueryDsl/Geo/BoundingBox/GeoBoundingBoxQuery.cs +++ b/src/Nest/QueryDsl/Geo/BoundingBox/GeoBoundingBoxQuery.cs @@ -13,6 +13,8 @@ public interface IGeoBoundingBoxQuery : IFieldNameQuery IBoundingBox BoundingBox { get; set; } GeoValidationMethod? ValidationMethod { get; set; } + + bool? IgnoreUnmapped { get; set; } } public class GeoBoundingBoxQuery : FieldNameQueryBase, IGeoBoundingBoxQuery @@ -20,6 +22,8 @@ public class GeoBoundingBoxQuery : FieldNameQueryBase, IGeoBoundingBoxQuery public IBoundingBox BoundingBox { get; set; } public GeoValidationMethod? ValidationMethod { get; set; } + + public bool? IgnoreUnmapped { get; set; } protected override bool Conditionless => IsConditionless(this); internal override void InternalWrapInContainer(IQueryContainer c) => c.GeoBoundingBox = this; @@ -35,6 +39,7 @@ public class GeoBoundingBoxQueryDescriptor protected override bool Conditionless => GeoBoundingBoxQuery.IsConditionless(this); IBoundingBox IGeoBoundingBoxQuery.BoundingBox { get; set; } GeoValidationMethod? IGeoBoundingBoxQuery.ValidationMethod { get; set; } + bool? IGeoBoundingBoxQuery.IgnoreUnmapped { get; set; } public GeoBoundingBoxQueryDescriptor BoundingBox(double topLeftLat, double topLeftLon, double bottomRightLat, double bottomRightLon) => BoundingBox(f => f.TopLeft(topLeftLat, topLeftLon).BottomRight(bottomRightLat, bottomRightLon)); @@ -49,6 +54,8 @@ public GeoBoundingBoxQueryDescriptor BoundingBox(Func a.BoundingBox = v?.Invoke(new BoundingBoxDescriptor())); public GeoBoundingBoxQueryDescriptor ValidationMethod(GeoValidationMethod? validation) => Assign(validation, (a, v) => a.ValidationMethod = v); + + public GeoBoundingBoxQueryDescriptor IgnoreUnmapped(bool? ignoreUnmapped = true) => Assign(ignoreUnmapped, (a, v) => a.IgnoreUnmapped = v); } internal class GeoBoundingBoxQueryFormatter : IJsonFormatter @@ -57,7 +64,8 @@ internal class GeoBoundingBoxQueryFormatter : IJsonFormatter() .Deserialize(ref reader, formatterResolver); break; + case 3: + query.IgnoreUnmapped = reader.ReadBoolean(); + break; } } else @@ -137,6 +148,16 @@ public void Serialize(ref JsonWriter writer, IGeoBoundingBoxQuery value, IJsonFo written = true; } + if (value.IgnoreUnmapped != null) + { + if (written) + writer.WriteValueSeparator(); + + writer.WritePropertyName("ignore_unmapped"); + writer.WriteBoolean(value.IgnoreUnmapped.Value); + written = true; + } + if (written) writer.WriteValueSeparator(); diff --git a/src/Nest/QueryDsl/Geo/Distance/GeoDistanceQuery.cs b/src/Nest/QueryDsl/Geo/Distance/GeoDistanceQuery.cs index 56ad6b707b6..bd0bfccbce3 100644 --- a/src/Nest/QueryDsl/Geo/Distance/GeoDistanceQuery.cs +++ b/src/Nest/QueryDsl/Geo/Distance/GeoDistanceQuery.cs @@ -15,6 +15,8 @@ public interface IGeoDistanceQuery : IFieldNameQuery GeoLocation Location { get; set; } GeoValidationMethod? ValidationMethod { get; set; } + + bool? IgnoreUnmapped { get; set; } } public class GeoDistanceQuery : FieldNameQueryBase, IGeoDistanceQuery @@ -23,6 +25,7 @@ public class GeoDistanceQuery : FieldNameQueryBase, IGeoDistanceQuery public GeoDistanceType? DistanceType { get; set; } public GeoLocation Location { get; set; } public GeoValidationMethod? ValidationMethod { get; set; } + public bool? IgnoreUnmapped { get; set; } protected override bool Conditionless => IsConditionless(this); internal override void InternalWrapInContainer(IQueryContainer c) => c.GeoDistance = this; @@ -40,6 +43,7 @@ public class GeoDistanceQueryDescriptor GeoDistanceType? IGeoDistanceQuery.DistanceType { get; set; } GeoLocation IGeoDistanceQuery.Location { get; set; } GeoValidationMethod? IGeoDistanceQuery.ValidationMethod { get; set; } + bool? IGeoDistanceQuery.IgnoreUnmapped { get; set; } public GeoDistanceQueryDescriptor Location(GeoLocation location) => Assign(location, (a, v) => a.Location = v); @@ -52,6 +56,8 @@ public class GeoDistanceQueryDescriptor public GeoDistanceQueryDescriptor DistanceType(GeoDistanceType? type) => Assign(type, (a, v) => a.DistanceType = v); public GeoDistanceQueryDescriptor ValidationMethod(GeoValidationMethod? validation) => Assign(validation, (a, v) => a.ValidationMethod = v); + + public GeoDistanceQueryDescriptor IgnoreUnmapped(bool? ignoreUnmapped = true) => Assign(ignoreUnmapped, (a, v) => a.IgnoreUnmapped = v); } internal class GeoDistanceQueryFormatter : IJsonFormatter @@ -62,7 +68,8 @@ internal class GeoDistanceQueryFormatter : IJsonFormatter { "boost", 1 }, { "validation_method", 2 }, { "distance", 3 }, - { "distance_type", 4 } + { "distance_type", 4 }, + { "ignore_unmapped", 5 } }; public IGeoDistanceQuery Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver) @@ -97,6 +104,9 @@ public IGeoDistanceQuery Deserialize(ref JsonReader reader, IJsonFormatterResolv query.DistanceType = formatterResolver.GetFormatter() .Deserialize(ref reader, formatterResolver); break; + case 5: + query.IgnoreUnmapped = reader.ReadNullableBoolean(); + break; } } else @@ -172,6 +182,16 @@ public void Serialize(ref JsonWriter writer, IGeoDistanceQuery value, IJsonForma written = true; } + if (value.IgnoreUnmapped != null) + { + if (written) + writer.WriteValueSeparator(); + + writer.WritePropertyName("ignore_unmapped"); + writer.WriteBoolean(value.IgnoreUnmapped.Value); + written = true; + } + if (written) writer.WriteValueSeparator(); diff --git a/src/Nest/QueryDsl/Geo/Polygon/GeoPolygonQuery.cs b/src/Nest/QueryDsl/Geo/Polygon/GeoPolygonQuery.cs index fedd6ce233c..d0d18ec9d5a 100644 --- a/src/Nest/QueryDsl/Geo/Polygon/GeoPolygonQuery.cs +++ b/src/Nest/QueryDsl/Geo/Polygon/GeoPolygonQuery.cs @@ -13,6 +13,8 @@ public interface IGeoPolygonQuery : IFieldNameQuery IEnumerable Points { get; set; } GeoValidationMethod? ValidationMethod { get; set; } + + bool? IgnoreUnmapped { get; set; } } public class GeoPolygonQuery : FieldNameQueryBase, IGeoPolygonQuery @@ -20,6 +22,8 @@ public class GeoPolygonQuery : FieldNameQueryBase, IGeoPolygonQuery public IEnumerable Points { get; set; } public GeoValidationMethod? ValidationMethod { get; set; } + + public bool? IgnoreUnmapped { get; set; } protected override bool Conditionless => IsConditionless(this); internal override void InternalWrapInContainer(IQueryContainer c) => c.GeoPolygon = this; @@ -34,12 +38,15 @@ public class GeoPolygonQueryDescriptor protected override bool Conditionless => GeoPolygonQuery.IsConditionless(this); IEnumerable IGeoPolygonQuery.Points { get; set; } GeoValidationMethod? IGeoPolygonQuery.ValidationMethod { get; set; } + bool? IGeoPolygonQuery.IgnoreUnmapped { get; set; } public GeoPolygonQueryDescriptor Points(IEnumerable points) => Assign(points, (a, v) => a.Points = v); public GeoPolygonQueryDescriptor Points(params GeoLocation[] points) => Assign(points, (a, v) => a.Points = v); public GeoPolygonQueryDescriptor ValidationMethod(GeoValidationMethod? validation) => Assign(validation, (a, v) => a.ValidationMethod = v); + + public GeoPolygonQueryDescriptor IgnoreUnmapped(bool? ignoreUnmapped = true) => Assign(ignoreUnmapped, (a, v) => a.IgnoreUnmapped = v); } internal class GeoPolygonQueryFormatter : IJsonFormatter @@ -48,7 +55,8 @@ internal class GeoPolygonQueryFormatter : IJsonFormatter { { "_name", 0 }, { "boost", 1 }, - { "validation_method", 2 } + { "validation_method", 2 }, + { "ignore_unmapped", 3 } }; public IGeoPolygonQuery Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver) @@ -75,6 +83,9 @@ public IGeoPolygonQuery Deserialize(ref JsonReader reader, IJsonFormatterResolve query.ValidationMethod = formatterResolver.GetFormatter() .Deserialize(ref reader, formatterResolver); break; + case 3: + query.IgnoreUnmapped = reader.ReadBoolean(); + break; } } else @@ -135,6 +146,16 @@ public void Serialize(ref JsonWriter writer, IGeoPolygonQuery value, IJsonFormat written = true; } + if (value.IgnoreUnmapped != null) + { + if (written) + writer.WriteValueSeparator(); + + writer.WritePropertyName("ignore_unmapped"); + writer.WriteBoolean(value.IgnoreUnmapped.Value); + written = true; + } + if (written) writer.WriteValueSeparator(); diff --git a/tests/Tests/QueryDsl/Geo/BoundingBox/GeoBoundingBoxQueryUsageTests.cs b/tests/Tests/QueryDsl/Geo/BoundingBox/GeoBoundingBoxQueryUsageTests.cs index e111d300e3a..30e11aaf9c1 100644 --- a/tests/Tests/QueryDsl/Geo/BoundingBox/GeoBoundingBoxQueryUsageTests.cs +++ b/tests/Tests/QueryDsl/Geo/BoundingBox/GeoBoundingBoxQueryUsageTests.cs @@ -30,7 +30,8 @@ public GeoBoundingBoxQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : b TopLeft = new GeoLocation(34, -34), BottomRight = new GeoLocation(-34, 34), }, - ValidationMethod = GeoValidationMethod.Strict + ValidationMethod = GeoValidationMethod.Strict, + IgnoreUnmapped = true }; protected override object QueryJson => new @@ -52,7 +53,8 @@ public GeoBoundingBoxQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : b lat = -34.0, lon = 34.0 } - } + }, + ignore_unmapped = true } }; @@ -66,6 +68,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor .BottomRight(-34, 34) ) .ValidationMethod(GeoValidationMethod.Strict) + .IgnoreUnmapped(true) ); } @@ -89,7 +92,8 @@ public GeoBoundingBoxWKTQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) { WellKnownText = "BBOX (-34, 34, 34, -34)" }, - ValidationMethod = GeoValidationMethod.Strict + ValidationMethod = GeoValidationMethod.Strict, + IgnoreUnmapped = true }; protected override object QueryJson => new @@ -102,7 +106,8 @@ public GeoBoundingBoxWKTQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) locationPoint = new { wkt = "BBOX (-34, 34, 34, -34)" - } + }, + ignore_unmapped = true } }; @@ -115,6 +120,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor .WellKnownText("BBOX (-34, 34, 34, -34)") ) .ValidationMethod(GeoValidationMethod.Strict) + .IgnoreUnmapped(true) ); } } diff --git a/tests/Tests/QueryDsl/Geo/Distance/GeoDistanceQueryUsageTests.cs b/tests/Tests/QueryDsl/Geo/Distance/GeoDistanceQueryUsageTests.cs index 93dd8fdb95e..f48fd6ebd8d 100644 --- a/tests/Tests/QueryDsl/Geo/Distance/GeoDistanceQueryUsageTests.cs +++ b/tests/Tests/QueryDsl/Geo/Distance/GeoDistanceQueryUsageTests.cs @@ -28,7 +28,8 @@ public GeoDistanceQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base DistanceType = GeoDistanceType.Arc, Location = new GeoLocation(34, -34), Distance = "200m", - ValidationMethod = GeoValidationMethod.IgnoreMalformed + ValidationMethod = GeoValidationMethod.IgnoreMalformed, + IgnoreUnmapped = true, }; protected override object QueryJson => new @@ -44,7 +45,8 @@ public GeoDistanceQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base { lat = 34.0, lon = -34.0 - } + }, + ignore_unmapped = true, } }; @@ -57,6 +59,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor .Location(34, -34) .Distance("200m") .ValidationMethod(GeoValidationMethod.IgnoreMalformed) + .IgnoreUnmapped(true) ); } } diff --git a/tests/Tests/QueryDsl/Geo/Polygon/GeoPolygonQueryUsageTests.cs b/tests/Tests/QueryDsl/Geo/Polygon/GeoPolygonQueryUsageTests.cs index 04e4563957a..501bab049ec 100644 --- a/tests/Tests/QueryDsl/Geo/Polygon/GeoPolygonQueryUsageTests.cs +++ b/tests/Tests/QueryDsl/Geo/Polygon/GeoPolygonQueryUsageTests.cs @@ -27,7 +27,8 @@ public GeoPolygonQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base( Name = "named_query", ValidationMethod = GeoValidationMethod.Strict, Points = new[] { new GeoLocation(45, -45), new GeoLocation(-34, 34), new GeoLocation(70, -70) }, - Field = Infer.Field(p => p.LocationPoint) + Field = Infer.Field(p => p.LocationPoint), + IgnoreUnmapped = true }; protected override object QueryJson => new @@ -45,7 +46,8 @@ public GeoPolygonQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base( new { lat = -34.0, lon = 34.0 }, new { lat = 70.0, lon = -70.0 }, } - } + }, + ignore_unmapped = true, } }; @@ -56,6 +58,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor .Field(p => p.LocationPoint) .ValidationMethod(GeoValidationMethod.Strict) .Points(new GeoLocation(45, -45), new GeoLocation(-34, 34), new GeoLocation(70, -70)) + .IgnoreUnmapped(true) ); } }