Skip to content

Add IgnoreUnmapped to GeoDistanceQuery, GeoBoundingBoxQuery and GeoPo… #6066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/Nest/QueryDsl/Geo/BoundingBox/GeoBoundingBoxQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ public interface IGeoBoundingBoxQuery : IFieldNameQuery
IBoundingBox BoundingBox { get; set; }

GeoValidationMethod? ValidationMethod { get; set; }

bool? IgnoreUnmapped { get; set; }
}

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;
Expand All @@ -35,6 +39,7 @@ public class GeoBoundingBoxQueryDescriptor<T>
protected override bool Conditionless => GeoBoundingBoxQuery.IsConditionless(this);
IBoundingBox IGeoBoundingBoxQuery.BoundingBox { get; set; }
GeoValidationMethod? IGeoBoundingBoxQuery.ValidationMethod { get; set; }
bool? IGeoBoundingBoxQuery.IgnoreUnmapped { get; set; }

public GeoBoundingBoxQueryDescriptor<T> BoundingBox(double topLeftLat, double topLeftLon, double bottomRightLat, double bottomRightLon) =>
BoundingBox(f => f.TopLeft(topLeftLat, topLeftLon).BottomRight(bottomRightLat, bottomRightLon));
Expand All @@ -49,6 +54,8 @@ public GeoBoundingBoxQueryDescriptor<T> BoundingBox(Func<BoundingBoxDescriptor,
Assign(boundingBoxSelector, (a, v) => a.BoundingBox = v?.Invoke(new BoundingBoxDescriptor()));

public GeoBoundingBoxQueryDescriptor<T> ValidationMethod(GeoValidationMethod? validation) => Assign(validation, (a, v) => a.ValidationMethod = v);

public GeoBoundingBoxQueryDescriptor<T> IgnoreUnmapped(bool? ignoreUnmapped = true) => Assign(ignoreUnmapped, (a, v) => a.IgnoreUnmapped = v);
}

internal class GeoBoundingBoxQueryFormatter : IJsonFormatter<IGeoBoundingBoxQuery>
Expand All @@ -57,7 +64,8 @@ internal class GeoBoundingBoxQueryFormatter : IJsonFormatter<IGeoBoundingBoxQuer
{
{ "_name", 0 },
{ "boost", 1 },
{ "validation_method", 2 }
{ "validation_method", 2 },
{ "ignore_unmapped", 3 }
};

public IGeoBoundingBoxQuery Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
Expand All @@ -84,6 +92,9 @@ public IGeoBoundingBoxQuery Deserialize(ref JsonReader reader, IJsonFormatterRes
query.ValidationMethod = formatterResolver.GetFormatter<GeoValidationMethod>()
.Deserialize(ref reader, formatterResolver);
break;
case 3:
query.IgnoreUnmapped = reader.ReadBoolean();
break;
}
}
else
Expand Down Expand Up @@ -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();

Expand Down
22 changes: 21 additions & 1 deletion src/Nest/QueryDsl/Geo/Distance/GeoDistanceQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -40,6 +43,7 @@ public class GeoDistanceQueryDescriptor<T>
GeoDistanceType? IGeoDistanceQuery.DistanceType { get; set; }
GeoLocation IGeoDistanceQuery.Location { get; set; }
GeoValidationMethod? IGeoDistanceQuery.ValidationMethod { get; set; }
bool? IGeoDistanceQuery.IgnoreUnmapped { get; set; }

public GeoDistanceQueryDescriptor<T> Location(GeoLocation location) => Assign(location, (a, v) => a.Location = v);

Expand All @@ -52,6 +56,8 @@ public class GeoDistanceQueryDescriptor<T>
public GeoDistanceQueryDescriptor<T> DistanceType(GeoDistanceType? type) => Assign(type, (a, v) => a.DistanceType = v);

public GeoDistanceQueryDescriptor<T> ValidationMethod(GeoValidationMethod? validation) => Assign(validation, (a, v) => a.ValidationMethod = v);

public GeoDistanceQueryDescriptor<T> IgnoreUnmapped(bool? ignoreUnmapped = true) => Assign(ignoreUnmapped, (a, v) => a.IgnoreUnmapped = v);
}

internal class GeoDistanceQueryFormatter : IJsonFormatter<IGeoDistanceQuery>
Expand All @@ -62,7 +68,8 @@ internal class GeoDistanceQueryFormatter : IJsonFormatter<IGeoDistanceQuery>
{ "boost", 1 },
{ "validation_method", 2 },
{ "distance", 3 },
{ "distance_type", 4 }
{ "distance_type", 4 },
{ "ignore_unmapped", 5 }
};

public IGeoDistanceQuery Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
Expand Down Expand Up @@ -97,6 +104,9 @@ public IGeoDistanceQuery Deserialize(ref JsonReader reader, IJsonFormatterResolv
query.DistanceType = formatterResolver.GetFormatter<GeoDistanceType>()
.Deserialize(ref reader, formatterResolver);
break;
case 5:
query.IgnoreUnmapped = reader.ReadNullableBoolean();
break;
}
}
else
Expand Down Expand Up @@ -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();

Expand Down
23 changes: 22 additions & 1 deletion src/Nest/QueryDsl/Geo/Polygon/GeoPolygonQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ public interface IGeoPolygonQuery : IFieldNameQuery
IEnumerable<GeoLocation> Points { get; set; }

GeoValidationMethod? ValidationMethod { get; set; }

bool? IgnoreUnmapped { get; set; }
}

public class GeoPolygonQuery : FieldNameQueryBase, IGeoPolygonQuery
{
public IEnumerable<GeoLocation> 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;
Expand All @@ -34,12 +38,15 @@ public class GeoPolygonQueryDescriptor<T>
protected override bool Conditionless => GeoPolygonQuery.IsConditionless(this);
IEnumerable<GeoLocation> IGeoPolygonQuery.Points { get; set; }
GeoValidationMethod? IGeoPolygonQuery.ValidationMethod { get; set; }
bool? IGeoPolygonQuery.IgnoreUnmapped { get; set; }

public GeoPolygonQueryDescriptor<T> Points(IEnumerable<GeoLocation> points) => Assign(points, (a, v) => a.Points = v);

public GeoPolygonQueryDescriptor<T> Points(params GeoLocation[] points) => Assign(points, (a, v) => a.Points = v);

public GeoPolygonQueryDescriptor<T> ValidationMethod(GeoValidationMethod? validation) => Assign(validation, (a, v) => a.ValidationMethod = v);

public GeoPolygonQueryDescriptor<T> IgnoreUnmapped(bool? ignoreUnmapped = true) => Assign(ignoreUnmapped, (a, v) => a.IgnoreUnmapped = v);
}

internal class GeoPolygonQueryFormatter : IJsonFormatter<IGeoPolygonQuery>
Expand All @@ -48,7 +55,8 @@ internal class GeoPolygonQueryFormatter : IJsonFormatter<IGeoPolygonQuery>
{
{ "_name", 0 },
{ "boost", 1 },
{ "validation_method", 2 }
{ "validation_method", 2 },
{ "ignore_unmapped", 3 }
};

public IGeoPolygonQuery Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
Expand All @@ -75,6 +83,9 @@ public IGeoPolygonQuery Deserialize(ref JsonReader reader, IJsonFormatterResolve
query.ValidationMethod = formatterResolver.GetFormatter<GeoValidationMethod>()
.Deserialize(ref reader, formatterResolver);
break;
case 3:
query.IgnoreUnmapped = reader.ReadBoolean();
break;
}
}
else
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,7 +53,8 @@ public GeoBoundingBoxQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : b
lat = -34.0,
lon = 34.0
}
}
},
ignore_unmapped = true
}
};

Expand All @@ -66,6 +68,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
.BottomRight(-34, 34)
)
.ValidationMethod(GeoValidationMethod.Strict)
.IgnoreUnmapped(true)
);
}

Expand All @@ -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
Expand All @@ -102,7 +106,8 @@ public GeoBoundingBoxWKTQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage)
locationPoint = new
{
wkt = "BBOX (-34, 34, 34, -34)"
}
},
ignore_unmapped = true
}
};

Expand All @@ -115,6 +120,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
.WellKnownText("BBOX (-34, 34, 34, -34)")
)
.ValidationMethod(GeoValidationMethod.Strict)
.IgnoreUnmapped(true)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,7 +45,8 @@ public GeoDistanceQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base
{
lat = 34.0,
lon = -34.0
}
},
ignore_unmapped = true,
}
};

Expand All @@ -57,6 +59,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
.Location(34, -34)
.Distance("200m")
.ValidationMethod(GeoValidationMethod.IgnoreMalformed)
.IgnoreUnmapped(true)
);
}
}
7 changes: 5 additions & 2 deletions tests/Tests/QueryDsl/Geo/Polygon/GeoPolygonQueryUsageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project>(p => p.LocationPoint)
Field = Infer.Field<Project>(p => p.LocationPoint),
IgnoreUnmapped = true
};

protected override object QueryJson => new
Expand All @@ -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,
}
};

Expand All @@ -56,6 +58,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
.Field(p => p.LocationPoint)
.ValidationMethod(GeoValidationMethod.Strict)
.Points(new GeoLocation(45, -45), new GeoLocation(-34, 34), new GeoLocation(70, -70))
.IgnoreUnmapped(true)
);
}
}