Skip to content

Commit 7578b56

Browse files
Add IgnoreUnmapped to GeoDistanceQuery, GeoBoundingBoxQuery and GeoPolygon (#6070) (#6084)
* Add IgnoreUnmapped to GeoDistanceQuery, GeoBoundingBoxQuery and GeoPolygonQuery * Resolve merge conflicts (cherry picked from commit 5c9eb4b) Co-authored-by: Alireza Ziaee <45371919+alrz1999@users.noreply.github.com>
1 parent 564148e commit 7578b56

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
@@ -18,6 +18,8 @@ public interface IGeoBoundingBoxQuery : IFieldNameQuery
1818
GeoExecution? Type { get; set; }
1919

2020
GeoValidationMethod? ValidationMethod { get; set; }
21+
22+
bool? IgnoreUnmapped { get; set; }
2123
}
2224

2325
public class GeoBoundingBoxQuery : FieldNameQueryBase, IGeoBoundingBoxQuery
@@ -26,6 +28,8 @@ public class GeoBoundingBoxQuery : FieldNameQueryBase, IGeoBoundingBoxQuery
2628
public GeoExecution? Type { get; set; }
2729

2830
public GeoValidationMethod? ValidationMethod { get; set; }
31+
32+
public bool? IgnoreUnmapped { get; set; }
2933
protected override bool Conditionless => IsConditionless(this);
3034

3135
internal override void InternalWrapInContainer(IQueryContainer c) => c.GeoBoundingBox = this;
@@ -42,6 +46,7 @@ public class GeoBoundingBoxQueryDescriptor<T>
4246
IBoundingBox IGeoBoundingBoxQuery.BoundingBox { get; set; }
4347
GeoExecution? IGeoBoundingBoxQuery.Type { get; set; }
4448
GeoValidationMethod? IGeoBoundingBoxQuery.ValidationMethod { get; set; }
49+
bool? IGeoBoundingBoxQuery.IgnoreUnmapped { get; set; }
4550

4651
public GeoBoundingBoxQueryDescriptor<T> BoundingBox(double topLeftLat, double topLeftLon, double bottomRightLat, double bottomRightLon) =>
4752
BoundingBox(f => f.TopLeft(topLeftLat, topLeftLon).BottomRight(bottomRightLat, bottomRightLon));
@@ -58,6 +63,8 @@ public GeoBoundingBoxQueryDescriptor<T> BoundingBox(Func<BoundingBoxDescriptor,
5863
public GeoBoundingBoxQueryDescriptor<T> Type(GeoExecution? type) => Assign(type, (a, v) => a.Type = v);
5964

6065
public GeoBoundingBoxQueryDescriptor<T> ValidationMethod(GeoValidationMethod? validation) => Assign(validation, (a, v) => a.ValidationMethod = v);
66+
67+
public GeoBoundingBoxQueryDescriptor<T> IgnoreUnmapped(bool? ignoreUnmapped = true) => Assign(ignoreUnmapped, (a, v) => a.IgnoreUnmapped = v);
6168
}
6269

6370
internal class GeoBoundingBoxQueryFormatter : IJsonFormatter<IGeoBoundingBoxQuery>
@@ -67,7 +74,8 @@ internal class GeoBoundingBoxQueryFormatter : IJsonFormatter<IGeoBoundingBoxQuer
6774
{ "_name", 0 },
6875
{ "boost", 1 },
6976
{ "validation_method", 2 },
70-
{ "type", 3 }
77+
{ "type", 3 },
78+
{ "ignore_unmapped", 4 }
7179
};
7280

7381
public IGeoBoundingBoxQuery Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
@@ -98,6 +106,9 @@ public IGeoBoundingBoxQuery Deserialize(ref JsonReader reader, IJsonFormatterRes
98106
query.Type = formatterResolver.GetFormatter<GeoExecution>()
99107
.Deserialize(ref reader, formatterResolver);
100108
break;
109+
case 4:
110+
query.IgnoreUnmapped = reader.ReadNullableBoolean();
111+
break;
101112
}
102113
}
103114
else
@@ -162,6 +173,16 @@ public void Serialize(ref JsonWriter writer, IGeoBoundingBoxQuery value, IJsonFo
162173
written = true;
163174
}
164175

176+
if (value.IgnoreUnmapped != null)
177+
{
178+
if (written)
179+
writer.WriteValueSeparator();
180+
181+
writer.WritePropertyName("ignore_unmapped");
182+
writer.WriteBoolean(value.IgnoreUnmapped.Value);
183+
written = true;
184+
}
185+
165186
if (written)
166187
writer.WriteValueSeparator();
167188

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

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

2020
GeoValidationMethod? ValidationMethod { get; set; }
21+
22+
bool? IgnoreUnmapped { get; set; }
2123
}
2224

2325
public class GeoDistanceQuery : FieldNameQueryBase, IGeoDistanceQuery
@@ -26,6 +28,7 @@ public class GeoDistanceQuery : FieldNameQueryBase, IGeoDistanceQuery
2628
public GeoDistanceType? DistanceType { get; set; }
2729
public GeoLocation Location { get; set; }
2830
public GeoValidationMethod? ValidationMethod { get; set; }
31+
public bool? IgnoreUnmapped { get; set; }
2932
protected override bool Conditionless => IsConditionless(this);
3033

3134
internal override void InternalWrapInContainer(IQueryContainer c) => c.GeoDistance = this;
@@ -43,6 +46,7 @@ public class GeoDistanceQueryDescriptor<T>
4346
GeoDistanceType? IGeoDistanceQuery.DistanceType { get; set; }
4447
GeoLocation IGeoDistanceQuery.Location { get; set; }
4548
GeoValidationMethod? IGeoDistanceQuery.ValidationMethod { get; set; }
49+
bool? IGeoDistanceQuery.IgnoreUnmapped { get; set; }
4650

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

@@ -55,6 +59,8 @@ public class GeoDistanceQueryDescriptor<T>
5559
public GeoDistanceQueryDescriptor<T> DistanceType(GeoDistanceType? type) => Assign(type, (a, v) => a.DistanceType = v);
5660

5761
public GeoDistanceQueryDescriptor<T> ValidationMethod(GeoValidationMethod? validation) => Assign(validation, (a, v) => a.ValidationMethod = v);
62+
63+
public GeoDistanceQueryDescriptor<T> IgnoreUnmapped(bool? ignoreUnmapped = true) => Assign(ignoreUnmapped, (a, v) => a.IgnoreUnmapped = v);
5864
}
5965

6066
internal class GeoDistanceQueryFormatter : IJsonFormatter<IGeoDistanceQuery>
@@ -65,7 +71,8 @@ internal class GeoDistanceQueryFormatter : IJsonFormatter<IGeoDistanceQuery>
6571
{ "boost", 1 },
6672
{ "validation_method", 2 },
6773
{ "distance", 3 },
68-
{ "distance_type", 4 }
74+
{ "distance_type", 4 },
75+
{ "ignore_unmapped", 5 }
6976
};
7077

7178
public IGeoDistanceQuery Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
@@ -100,6 +107,9 @@ public IGeoDistanceQuery Deserialize(ref JsonReader reader, IJsonFormatterResolv
100107
query.DistanceType = formatterResolver.GetFormatter<GeoDistanceType>()
101108
.Deserialize(ref reader, formatterResolver);
102109
break;
110+
case 5:
111+
query.IgnoreUnmapped = reader.ReadNullableBoolean();
112+
break;
103113
}
104114
}
105115
else
@@ -175,6 +185,16 @@ public void Serialize(ref JsonWriter writer, IGeoDistanceQuery value, IJsonForma
175185
written = true;
176186
}
177187

188+
if (value.IgnoreUnmapped != null)
189+
{
190+
if (written)
191+
writer.WriteValueSeparator();
192+
193+
writer.WritePropertyName("ignore_unmapped");
194+
writer.WriteBoolean(value.IgnoreUnmapped.Value);
195+
written = true;
196+
}
197+
178198
if (written)
179199
writer.WriteValueSeparator();
180200

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

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

1818
GeoValidationMethod? ValidationMethod { get; set; }
19+
20+
bool? IgnoreUnmapped { get; set; }
1921
}
2022

2123
public class GeoPolygonQuery : FieldNameQueryBase, IGeoPolygonQuery
2224
{
2325
public IEnumerable<GeoLocation> Points { get; set; }
2426

2527
public GeoValidationMethod? ValidationMethod { get; set; }
28+
29+
public bool? IgnoreUnmapped { get; set; }
2630
protected override bool Conditionless => IsConditionless(this);
2731

2832
internal override void InternalWrapInContainer(IQueryContainer c) => c.GeoPolygon = this;
@@ -37,12 +41,15 @@ public class GeoPolygonQueryDescriptor<T>
3741
protected override bool Conditionless => GeoPolygonQuery.IsConditionless(this);
3842
IEnumerable<GeoLocation> IGeoPolygonQuery.Points { get; set; }
3943
GeoValidationMethod? IGeoPolygonQuery.ValidationMethod { get; set; }
44+
bool? IGeoPolygonQuery.IgnoreUnmapped { get; set; }
4045

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

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

4550
public GeoPolygonQueryDescriptor<T> ValidationMethod(GeoValidationMethod? validation) => Assign(validation, (a, v) => a.ValidationMethod = v);
51+
52+
public GeoPolygonQueryDescriptor<T> IgnoreUnmapped(bool? ignoreUnmapped = true) => Assign(ignoreUnmapped, (a, v) => a.IgnoreUnmapped = v);
4653
}
4754

4855
internal class GeoPolygonQueryFormatter : IJsonFormatter<IGeoPolygonQuery>
@@ -51,7 +58,8 @@ internal class GeoPolygonQueryFormatter : IJsonFormatter<IGeoPolygonQuery>
5158
{
5259
{ "_name", 0 },
5360
{ "boost", 1 },
54-
{ "validation_method", 2 }
61+
{ "validation_method", 2 },
62+
{ "ignore_unmapped", 3 }
5563
};
5664

5765
public IGeoPolygonQuery Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
@@ -78,6 +86,9 @@ public IGeoPolygonQuery Deserialize(ref JsonReader reader, IJsonFormatterResolve
7886
query.ValidationMethod = formatterResolver.GetFormatter<GeoValidationMethod>()
7987
.Deserialize(ref reader, formatterResolver);
8088
break;
89+
case 3:
90+
query.IgnoreUnmapped = reader.ReadNullableBoolean();
91+
break;
8192
}
8293
}
8394
else
@@ -138,6 +149,16 @@ public void Serialize(ref JsonWriter writer, IGeoPolygonQuery value, IJsonFormat
138149
written = true;
139150
}
140151

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

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public GeoBoundingBoxQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : b
3131
BottomRight = new GeoLocation(-34, 34),
3232
},
3333
Type = GeoExecution.Indexed,
34-
ValidationMethod = GeoValidationMethod.Strict
34+
ValidationMethod = GeoValidationMethod.Strict,
35+
IgnoreUnmapped = true
3536
};
3637

3738
protected override object QueryJson => new
@@ -54,7 +55,8 @@ public GeoBoundingBoxQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : b
5455
lat = -34.0,
5556
lon = 34.0
5657
}
57-
}
58+
},
59+
ignore_unmapped = true
5860
}
5961
};
6062

@@ -69,6 +71,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
6971
)
7072
.ValidationMethod(GeoValidationMethod.Strict)
7173
.Type(GeoExecution.Indexed)
74+
.IgnoreUnmapped(true)
7275
);
7376
}
7477

@@ -93,7 +96,8 @@ public GeoBoundingBoxWKTQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage)
9396
WellKnownText = "BBOX (-34, 34, 34, -34)"
9497
},
9598
Type = GeoExecution.Indexed,
96-
ValidationMethod = GeoValidationMethod.Strict
99+
ValidationMethod = GeoValidationMethod.Strict,
100+
IgnoreUnmapped = true
97101
};
98102

99103
protected override object QueryJson => new
@@ -107,7 +111,8 @@ public GeoBoundingBoxWKTQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage)
107111
locationPoint = new
108112
{
109113
wkt = "BBOX (-34, 34, 34, -34)"
110-
}
114+
},
115+
ignore_unmapped = true
111116
}
112117
};
113118

@@ -121,6 +126,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
121126
)
122127
.ValidationMethod(GeoValidationMethod.Strict)
123128
.Type(GeoExecution.Indexed)
129+
.IgnoreUnmapped(true)
124130
);
125131
}
126132
}

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)