Skip to content

Commit a3c5540

Browse files
committed
Add IgnoreUnmapped to GeoDistanceQuery, GeoBoundingBoxQuery and GeoPolygonQuery
1 parent fac9c1b commit a3c5540

File tree

6 files changed

+85
-11
lines changed

6 files changed

+85
-11
lines changed

src/Nest/QueryDsl/Geo/BoundingBox/GeoBoundingBoxQuery.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ public interface IGeoBoundingBoxQuery : IFieldNameQuery
1313
IBoundingBox BoundingBox { get; set; }
1414

1515
GeoValidationMethod? ValidationMethod { get; set; }
16+
17+
bool? IgnoreUnmapped { get; set; }
1618
}
1719

1820
public class GeoBoundingBoxQuery : FieldNameQueryBase, IGeoBoundingBoxQuery
1921
{
2022
public IBoundingBox BoundingBox { get; set; }
2123

2224
public GeoValidationMethod? ValidationMethod { get; set; }
25+
26+
public bool? IgnoreUnmapped { get; set; }
2327
protected override bool Conditionless => IsConditionless(this);
2428

2529
internal override void InternalWrapInContainer(IQueryContainer c) => c.GeoBoundingBox = this;
@@ -35,6 +39,7 @@ public class GeoBoundingBoxQueryDescriptor<T>
3539
protected override bool Conditionless => GeoBoundingBoxQuery.IsConditionless(this);
3640
IBoundingBox IGeoBoundingBoxQuery.BoundingBox { get; set; }
3741
GeoValidationMethod? IGeoBoundingBoxQuery.ValidationMethod { get; set; }
42+
bool? IGeoBoundingBoxQuery.IgnoreUnmapped { get; set; }
3843

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

5156
public GeoBoundingBoxQueryDescriptor<T> ValidationMethod(GeoValidationMethod? validation) => Assign(validation, (a, v) => a.ValidationMethod = v);
57+
58+
public GeoBoundingBoxQueryDescriptor<T> IgnoreUnmapped(bool? ignoreUnmapped = true) => Assign(ignoreUnmapped, (a, v) => a.IgnoreUnmapped = v);
5259
}
5360

5461
internal class GeoBoundingBoxQueryFormatter : IJsonFormatter<IGeoBoundingBoxQuery>
@@ -57,7 +64,8 @@ internal class GeoBoundingBoxQueryFormatter : IJsonFormatter<IGeoBoundingBoxQuer
5764
{
5865
{ "_name", 0 },
5966
{ "boost", 1 },
60-
{ "validation_method", 2 }
67+
{ "validation_method", 2 },
68+
{ "ignore_unmapped", 3 }
6169
};
6270

6371
public IGeoBoundingBoxQuery Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
@@ -84,6 +92,9 @@ public IGeoBoundingBoxQuery Deserialize(ref JsonReader reader, IJsonFormatterRes
8492
query.ValidationMethod = formatterResolver.GetFormatter<GeoValidationMethod>()
8593
.Deserialize(ref reader, formatterResolver);
8694
break;
95+
case 3:
96+
query.IgnoreUnmapped = reader.ReadBoolean();
97+
break;
8798
}
8899
}
89100
else
@@ -137,6 +148,16 @@ public void Serialize(ref JsonWriter writer, IGeoBoundingBoxQuery value, IJsonFo
137148
written = true;
138149
}
139150

151+
if (value.IgnoreUnmapped != null)
152+
{
153+
if (written)
154+
writer.WriteValueSeparator();
155+
156+
writer.WritePropertyName("ignore_unmapped");
157+
writer.WriteBoolean(value.IgnoreUnmapped.Value);
158+
written = true;
159+
}
160+
140161
if (written)
141162
writer.WriteValueSeparator();
142163

src/Nest/QueryDsl/Geo/Distance/GeoDistanceQuery.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public interface IGeoDistanceQuery : IFieldNameQuery
1515
GeoLocation Location { get; set; }
1616

1717
GeoValidationMethod? ValidationMethod { get; set; }
18+
19+
bool? IgnoreUnmapped { get; set; }
1820
}
1921

2022
public class GeoDistanceQuery : FieldNameQueryBase, IGeoDistanceQuery
@@ -23,6 +25,7 @@ public class GeoDistanceQuery : FieldNameQueryBase, IGeoDistanceQuery
2325
public GeoDistanceType? DistanceType { get; set; }
2426
public GeoLocation Location { get; set; }
2527
public GeoValidationMethod? ValidationMethod { get; set; }
28+
public bool? IgnoreUnmapped { get; set; }
2629
protected override bool Conditionless => IsConditionless(this);
2730

2831
internal override void InternalWrapInContainer(IQueryContainer c) => c.GeoDistance = this;
@@ -40,6 +43,7 @@ public class GeoDistanceQueryDescriptor<T>
4043
GeoDistanceType? IGeoDistanceQuery.DistanceType { get; set; }
4144
GeoLocation IGeoDistanceQuery.Location { get; set; }
4245
GeoValidationMethod? IGeoDistanceQuery.ValidationMethod { get; set; }
46+
bool? IGeoDistanceQuery.IgnoreUnmapped { get; set; }
4347

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

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

5458
public GeoDistanceQueryDescriptor<T> ValidationMethod(GeoValidationMethod? validation) => Assign(validation, (a, v) => a.ValidationMethod = v);
59+
60+
public GeoDistanceQueryDescriptor<T> IgnoreUnmapped(bool? ignoreUnmapped = true) => Assign(ignoreUnmapped, (a, v) => a.IgnoreUnmapped = v);
5561
}
5662

5763
internal class GeoDistanceQueryFormatter : IJsonFormatter<IGeoDistanceQuery>
@@ -62,7 +68,8 @@ internal class GeoDistanceQueryFormatter : IJsonFormatter<IGeoDistanceQuery>
6268
{ "boost", 1 },
6369
{ "validation_method", 2 },
6470
{ "distance", 3 },
65-
{ "distance_type", 4 }
71+
{ "distance_type", 4 },
72+
{ "ignore_unmapped", 5 }
6673
};
6774

6875
public IGeoDistanceQuery Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
@@ -97,6 +104,9 @@ public IGeoDistanceQuery Deserialize(ref JsonReader reader, IJsonFormatterResolv
97104
query.DistanceType = formatterResolver.GetFormatter<GeoDistanceType>()
98105
.Deserialize(ref reader, formatterResolver);
99106
break;
107+
case 5:
108+
query.IgnoreUnmapped = reader.ReadNullableBoolean();
109+
break;
100110
}
101111
}
102112
else
@@ -172,6 +182,16 @@ public void Serialize(ref JsonWriter writer, IGeoDistanceQuery value, IJsonForma
172182
written = true;
173183
}
174184

185+
if (value.IgnoreUnmapped != null)
186+
{
187+
if (written)
188+
writer.WriteValueSeparator();
189+
190+
writer.WritePropertyName("ignore_unmapped");
191+
writer.WriteBoolean(value.IgnoreUnmapped.Value);
192+
written = true;
193+
}
194+
175195
if (written)
176196
writer.WriteValueSeparator();
177197

src/Nest/QueryDsl/Geo/Polygon/GeoPolygonQuery.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ public interface IGeoPolygonQuery : IFieldNameQuery
1313
IEnumerable<GeoLocation> Points { get; set; }
1414

1515
GeoValidationMethod? ValidationMethod { get; set; }
16+
17+
bool? IgnoreUnmapped { get; set; }
1618
}
1719

1820
public class GeoPolygonQuery : FieldNameQueryBase, IGeoPolygonQuery
1921
{
2022
public IEnumerable<GeoLocation> Points { get; set; }
2123

2224
public GeoValidationMethod? ValidationMethod { get; set; }
25+
26+
public bool? IgnoreUnmapped { get; set; }
2327
protected override bool Conditionless => IsConditionless(this);
2428

2529
internal override void InternalWrapInContainer(IQueryContainer c) => c.GeoPolygon = this;
@@ -34,12 +38,15 @@ public class GeoPolygonQueryDescriptor<T>
3438
protected override bool Conditionless => GeoPolygonQuery.IsConditionless(this);
3539
IEnumerable<GeoLocation> IGeoPolygonQuery.Points { get; set; }
3640
GeoValidationMethod? IGeoPolygonQuery.ValidationMethod { get; set; }
41+
bool? IGeoPolygonQuery.IgnoreUnmapped { get; set; }
3742

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

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

4247
public GeoPolygonQueryDescriptor<T> ValidationMethod(GeoValidationMethod? validation) => Assign(validation, (a, v) => a.ValidationMethod = v);
48+
49+
public GeoPolygonQueryDescriptor<T> IgnoreUnmapped(bool? ignoreUnmapped = true) => Assign(ignoreUnmapped, (a, v) => a.IgnoreUnmapped = v);
4350
}
4451

4552
internal class GeoPolygonQueryFormatter : IJsonFormatter<IGeoPolygonQuery>
@@ -48,7 +55,8 @@ internal class GeoPolygonQueryFormatter : IJsonFormatter<IGeoPolygonQuery>
4855
{
4956
{ "_name", 0 },
5057
{ "boost", 1 },
51-
{ "validation_method", 2 }
58+
{ "validation_method", 2 },
59+
{ "ignore_unmapped", 3 }
5260
};
5361

5462
public IGeoPolygonQuery Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
@@ -75,6 +83,9 @@ public IGeoPolygonQuery Deserialize(ref JsonReader reader, IJsonFormatterResolve
7583
query.ValidationMethod = formatterResolver.GetFormatter<GeoValidationMethod>()
7684
.Deserialize(ref reader, formatterResolver);
7785
break;
86+
case 3:
87+
query.IgnoreUnmapped = reader.ReadBoolean();
88+
break;
7889
}
7990
}
8091
else
@@ -135,6 +146,16 @@ public void Serialize(ref JsonWriter writer, IGeoPolygonQuery value, IJsonFormat
135146
written = true;
136147
}
137148

149+
if (value.IgnoreUnmapped != null)
150+
{
151+
if (written)
152+
writer.WriteValueSeparator();
153+
154+
writer.WritePropertyName("ignore_unmapped");
155+
writer.WriteBoolean(value.IgnoreUnmapped.Value);
156+
written = true;
157+
}
158+
138159
if (written)
139160
writer.WriteValueSeparator();
140161

tests/Tests/QueryDsl/Geo/BoundingBox/GeoBoundingBoxQueryUsageTests.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public GeoBoundingBoxQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : b
3030
TopLeft = new GeoLocation(34, -34),
3131
BottomRight = new GeoLocation(-34, 34),
3232
},
33-
ValidationMethod = GeoValidationMethod.Strict
33+
ValidationMethod = GeoValidationMethod.Strict,
34+
IgnoreUnmapped = true
3435
};
3536

3637
protected override object QueryJson => new
@@ -52,7 +53,8 @@ public GeoBoundingBoxQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : b
5253
lat = -34.0,
5354
lon = 34.0
5455
}
55-
}
56+
},
57+
ignore_unmapped = true
5658
}
5759
};
5860

@@ -66,6 +68,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
6668
.BottomRight(-34, 34)
6769
)
6870
.ValidationMethod(GeoValidationMethod.Strict)
71+
.IgnoreUnmapped(true)
6972
);
7073
}
7174

@@ -89,7 +92,8 @@ public GeoBoundingBoxWKTQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage)
8992
{
9093
WellKnownText = "BBOX (-34, 34, 34, -34)"
9194
},
92-
ValidationMethod = GeoValidationMethod.Strict
95+
ValidationMethod = GeoValidationMethod.Strict,
96+
IgnoreUnmapped = true
9397
};
9498

9599
protected override object QueryJson => new
@@ -102,7 +106,8 @@ public GeoBoundingBoxWKTQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage)
102106
locationPoint = new
103107
{
104108
wkt = "BBOX (-34, 34, 34, -34)"
105-
}
109+
},
110+
ignore_unmapped = true
106111
}
107112
};
108113

@@ -115,6 +120,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
115120
.WellKnownText("BBOX (-34, 34, 34, -34)")
116121
)
117122
.ValidationMethod(GeoValidationMethod.Strict)
123+
.IgnoreUnmapped(true)
118124
);
119125
}
120126
}

tests/Tests/QueryDsl/Geo/Distance/GeoDistanceQueryUsageTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public GeoDistanceQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base
2828
DistanceType = GeoDistanceType.Arc,
2929
Location = new GeoLocation(34, -34),
3030
Distance = "200m",
31-
ValidationMethod = GeoValidationMethod.IgnoreMalformed
31+
ValidationMethod = GeoValidationMethod.IgnoreMalformed,
32+
IgnoreUnmapped = true,
3233
};
3334

3435
protected override object QueryJson => new
@@ -44,7 +45,8 @@ public GeoDistanceQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base
4445
{
4546
lat = 34.0,
4647
lon = -34.0
47-
}
48+
},
49+
ignore_unmapped = true,
4850
}
4951
};
5052

@@ -57,6 +59,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
5759
.Location(34, -34)
5860
.Distance("200m")
5961
.ValidationMethod(GeoValidationMethod.IgnoreMalformed)
62+
.IgnoreUnmapped(true)
6063
);
6164
}
6265
}

tests/Tests/QueryDsl/Geo/Polygon/GeoPolygonQueryUsageTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public GeoPolygonQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(
2727
Name = "named_query",
2828
ValidationMethod = GeoValidationMethod.Strict,
2929
Points = new[] { new GeoLocation(45, -45), new GeoLocation(-34, 34), new GeoLocation(70, -70) },
30-
Field = Infer.Field<Project>(p => p.LocationPoint)
30+
Field = Infer.Field<Project>(p => p.LocationPoint),
31+
IgnoreUnmapped = true
3132
};
3233

3334
protected override object QueryJson => new
@@ -45,7 +46,8 @@ public GeoPolygonQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(
4546
new { lat = -34.0, lon = 34.0 },
4647
new { lat = 70.0, lon = -70.0 },
4748
}
48-
}
49+
},
50+
ignore_unmapped = true,
4951
}
5052
};
5153

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

0 commit comments

Comments
 (0)