Skip to content

Commit 1055eb2

Browse files
authored
Obsolete IgnoreUnmapped on IGeoShape (#3214)
* Obsolete IgnoreUnmapped on IGeoShape This commit deprecates IgnoreUnmapped on IGeoShape by applying Obsolete attribute. IgnoreUnmapped exists at the same level as _name and boost on a geo_shape query. Map IgnoreUnmapped from IGeoShape.IgnoreUnmapped to IGeoShapeQuery.IgnoreUnmapped if assigned.
1 parent ba92b94 commit 1055eb2

File tree

15 files changed

+246
-99
lines changed

15 files changed

+246
-99
lines changed

src/Nest/QueryDsl/Geo/Shape/Circle/GeoShapeCircleQuery.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,24 @@ public interface IGeoShapeCircleQuery : IGeoShapeQuery
1111

1212
public class GeoShapeCircleQuery : GeoShapeQueryBase, IGeoShapeCircleQuery
1313
{
14+
private ICircleGeoShape _shape;
1415
protected override bool Conditionless => IsConditionless(this);
15-
public ICircleGeoShape Shape { get; set; }
16+
17+
public ICircleGeoShape Shape
18+
{
19+
get => _shape;
20+
set
21+
{
22+
#pragma warning disable 618
23+
if (value?.IgnoreUnmapped != null)
24+
{
25+
IgnoreUnmapped = value.IgnoreUnmapped;
26+
value.IgnoreUnmapped = null;
27+
}
28+
#pragma warning restore 618
29+
_shape = value;
30+
}
31+
}
1632

1733
internal override void InternalWrapInContainer(IQueryContainer c) => c.GeoShape = this;
1834

@@ -30,21 +46,21 @@ public GeoShapeCircleQueryDescriptor<T> Coordinates(GeoCoordinate coordinates, b
3046
{
3147
a.Shape = a.Shape ?? new CircleGeoShape();
3248
a.Shape.Coordinates = coordinates;
33-
a.Shape.IgnoreUnmapped = ignoreUnmapped;
49+
a.IgnoreUnmapped = ignoreUnmapped;
3450
});
3551

3652
public GeoShapeCircleQueryDescriptor<T> Coordinates(double longitude, double latitude, bool? ignoreUnmapped = null) => Assign(a =>
3753
{
3854
a.Shape = a.Shape ?? new CircleGeoShape();
3955
a.Shape.Coordinates = new GeoCoordinate(latitude, longitude);
40-
a.Shape.IgnoreUnmapped = ignoreUnmapped;
56+
a.IgnoreUnmapped = ignoreUnmapped;
4157
});
4258

4359
public GeoShapeCircleQueryDescriptor<T> Radius(string radius, bool? ignoreUnmapped = null) => Assign(a =>
4460
{
4561
a.Shape = a.Shape ?? new CircleGeoShape();
4662
a.Shape.Radius = radius;
47-
a.Shape.IgnoreUnmapped = ignoreUnmapped;
63+
a.IgnoreUnmapped = ignoreUnmapped;
4864
});
4965
}
5066
}

src/Nest/QueryDsl/Geo/Shape/Envelope/GeoShapeEnvelopeQuery.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,24 @@ public interface IGeoShapeEnvelopeQuery : IGeoShapeQuery
1212

1313
public class GeoShapeEnvelopeQuery : GeoShapeQueryBase, IGeoShapeEnvelopeQuery
1414
{
15+
private IEnvelopeGeoShape _shape;
1516
protected override bool Conditionless => IsConditionless(this);
16-
public IEnvelopeGeoShape Shape { get; set; }
17+
18+
public IEnvelopeGeoShape Shape
19+
{
20+
get => _shape;
21+
set
22+
{
23+
#pragma warning disable 618
24+
if (value?.IgnoreUnmapped != null)
25+
{
26+
IgnoreUnmapped = value.IgnoreUnmapped;
27+
value.IgnoreUnmapped = null;
28+
}
29+
#pragma warning restore 618
30+
_shape = value;
31+
}
32+
}
1733

1834
internal override void InternalWrapInContainer(IQueryContainer c) => c.GeoShape = this;
1935
internal static bool IsConditionless(IGeoShapeEnvelopeQuery q) => q.Field.IsConditionless() || q.Shape == null || !q.Shape.Coordinates.HasAny();
@@ -30,7 +46,7 @@ public GeoShapeEnvelopeQueryDescriptor<T> Coordinates(IEnumerable<GeoCoordinate>
3046
{
3147
a.Shape = a.Shape ?? new EnvelopeGeoShape();
3248
a.Shape.Coordinates = coordinates;
33-
a.Shape.IgnoreUnmapped = ignoreUnmapped;
49+
a.IgnoreUnmapped = ignoreUnmapped;
3450
});
3551
}
3652
}

src/Nest/QueryDsl/Geo/Shape/GeoShapeBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public interface IGeoShape
2020
/// This can be useful when querying multiple indexes which might have different mappings.
2121
/// </summary>
2222
[JsonProperty("ignore_unmapped")]
23+
[Obsolete("Removed in NEST 7.x. Use IgnoreUnmapped on IGeoShapeQuery")]
2324
bool? IgnoreUnmapped { get; set; }
2425
}
2526

@@ -31,6 +32,7 @@ public abstract class GeoShapeBase : IGeoShape
3132
public string Type { get; protected set; }
3233

3334
/// <inheritdoc />
35+
[Obsolete("Removed in NEST 7.x. Use IgnoreUnmapped on IGeoShapeQuery")]
3436
public bool? IgnoreUnmapped { get; set; }
3537
}
3638

src/Nest/QueryDsl/Geo/Shape/GeoShapeQueryJsonConverter.cs

Lines changed: 35 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
namespace Nest
88
{
99
/// <summary>
10-
/// Marks an instance where _name and boost do not exist as children of the variable field but as siblings
10+
/// Marks an instance where _name, boost and ignore_unmapped do
11+
/// not exist as children of the variable field but as siblings
1112
/// </summary>
12-
internal class GeoShapeQueryFieldNameConverter : FieldNameQueryJsonConverter<GeoShapeCircleQuery>
13+
internal class GeoShapeQueryFieldNameConverter : ReserializeJsonConverter<GeoShapeCircleQuery, IGeoShapeQuery>
1314
{
14-
private static readonly string[] SkipProperties = {"boost", "_name"};
15+
private static readonly string[] SkipProperties = {"boost", "_name", "ignore_unmapped"};
1516
protected override bool SkipWriteProperty(string propertyName) => SkipProperties.Contains(propertyName);
1617

17-
protected override void SerializeJson(JsonWriter writer, object value, IFieldNameQuery castValue, JsonSerializer serializer)
18+
protected override void SerializeJson(JsonWriter writer, object value, IGeoShapeQuery castValue, JsonSerializer serializer)
1819
{
1920
var fieldName = castValue.Field;
2021
if (fieldName == null) return;
@@ -26,8 +27,10 @@ protected override void SerializeJson(JsonWriter writer, object value, IFieldNam
2627
writer.WriteStartObject();
2728
var name = castValue.Name;
2829
var boost = castValue.Boost;
30+
var ignoreUnmapped = castValue.IgnoreUnmapped;
2931
if (!name.IsNullOrEmpty()) writer.WriteProperty(serializer, "_name", name);
3032
if (boost != null) writer.WriteProperty(serializer, "boost", boost);
33+
if (ignoreUnmapped != null) writer.WriteProperty(serializer, "ignore_unmapped", ignoreUnmapped);
3134
writer.WritePropertyName(field);
3235
this.Reserialize(writer, value, serializer);
3336
writer.WriteEndObject();
@@ -40,22 +43,36 @@ internal class GeoShapeQueryJsonConverter : JsonConverter
4043
public override bool CanRead => true;
4144
public override bool CanWrite => false;
4245

46+
public virtual T GetCoordinates<T>(JToken shape, JsonSerializer serializer)
47+
{
48+
var coordinates = shape["coordinates"];
49+
return coordinates != null
50+
? coordinates.ToObject<T>(serializer)
51+
: default(T);
52+
}
53+
4354
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
4455
{
4556
var j = JObject.Load(reader);
4657
if (j == null || !j.HasValues) return null;
4758

4859
double? boost = null;
4960
string name = null;
50-
if (j.TryGetValue("boost", out var b) && (b.Type != JTokenType.Array && b.Type != JTokenType.Object))
61+
bool? ignoreUnmapped = null;
62+
if (j.TryGetValue("boost", out var boostToken) && (boostToken.Type != JTokenType.Array && boostToken.Type != JTokenType.Object))
5163
{
5264
j.Remove("boost");
53-
boost = b.Value<double?>();
65+
boost = boostToken.Value<double?>();
5466
}
55-
if (j.TryGetValue("_name", out var n) && n.Type == JTokenType.String)
67+
if (j.TryGetValue("_name", out var nameToken) && nameToken.Type == JTokenType.String)
5668
{
5769
j.Remove("_name");
58-
name = n.Value<string>();
70+
name = nameToken.Value<string>();
71+
}
72+
if (j.TryGetValue("ignore_unmapped", out var ignoreUnmappedToken) && ignoreUnmappedToken.Type == JTokenType.Boolean)
73+
{
74+
j.Remove("ignore_unmapped");
75+
ignoreUnmapped = ignoreUnmappedToken.Value<bool?>();
5976
}
6077
var firstProp = j.Properties().FirstOrDefault();
6178
if (firstProp == null) return null;
@@ -77,6 +94,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
7794
query.Name = name;
7895
query.Field = field;
7996
query.Relation = relation;
97+
query.IgnoreUnmapped = ignoreUnmapped;
8098
return query;
8199
}
82100

@@ -87,74 +105,33 @@ private static IGeoShapeQuery ParseShapeQuery(JToken shape, JsonSerializer seria
87105
{
88106
var type = shape["type"];
89107
var typeName = type?.Value<string>();
90-
var ignoreUnmapped = shape["ignore_unmapped"]?.Value<bool?>();
91-
92108
var geometry = GeoShapeConverter.ReadJToken(shape, serializer);
93-
94109
switch (typeName)
95110
{
96111
case "circle":
97-
return new GeoShapeCircleQuery
98-
{
99-
Shape = SetIgnoreUnmapped(geometry as ICircleGeoShape, ignoreUnmapped)
100-
};
112+
return new GeoShapeCircleQuery { Shape = geometry as ICircleGeoShape };
101113
case "envelope":
102-
return new GeoShapeEnvelopeQuery
103-
{
104-
Shape = SetIgnoreUnmapped(geometry as IEnvelopeGeoShape, ignoreUnmapped)
105-
};
114+
return new GeoShapeEnvelopeQuery { Shape = geometry as IEnvelopeGeoShape };
106115
case "linestring":
107-
return new GeoShapeLineStringQuery
108-
{
109-
Shape = SetIgnoreUnmapped(geometry as ILineStringGeoShape, ignoreUnmapped)
110-
};
116+
return new GeoShapeLineStringQuery { Shape = geometry as ILineStringGeoShape };
111117
case "multilinestring":
112-
return new GeoShapeMultiLineStringQuery
113-
{
114-
Shape = SetIgnoreUnmapped(geometry as IMultiLineStringGeoShape, ignoreUnmapped)
115-
};
118+
return new GeoShapeMultiLineStringQuery { Shape = geometry as IMultiLineStringGeoShape };
116119
case "point":
117-
return new GeoShapePointQuery
118-
{
119-
Shape = SetIgnoreUnmapped(geometry as IPointGeoShape, ignoreUnmapped)
120-
};
120+
return new GeoShapePointQuery { Shape = geometry as IPointGeoShape };
121121
case "multipoint":
122-
return new GeoShapeMultiPointQuery
123-
{
124-
Shape = SetIgnoreUnmapped(geometry as IMultiPointGeoShape, ignoreUnmapped)
125-
};
122+
return new GeoShapeMultiPointQuery { Shape = geometry as IMultiPointGeoShape };
126123
case "polygon":
127-
return new GeoShapePolygonQuery
128-
{
129-
Shape = SetIgnoreUnmapped(geometry as IPolygonGeoShape, ignoreUnmapped)
130-
};
124+
return new GeoShapePolygonQuery { Shape = geometry as IPolygonGeoShape };
131125
case "multipolygon":
132-
return new GeoShapeMultiPolygonQuery
133-
{
134-
Shape = SetIgnoreUnmapped(geometry as IMultiPolygonGeoShape, ignoreUnmapped)
135-
};
126+
return new GeoShapeMultiPolygonQuery { Shape = geometry as IMultiPolygonGeoShape };
136127
case "geometrycollection":
137-
var geometryCollection = geometry as IGeometryCollection;
138-
if (geometryCollection != null)
139-
{
140-
foreach (var innerGeometry in geometryCollection.Geometries)
141-
SetIgnoreUnmapped(innerGeometry, ignoreUnmapped);
142-
}
143-
144-
return new GeoShapeGeometryCollectionQuery { Shape = geometryCollection };
128+
return new GeoShapeGeometryCollectionQuery { Shape = geometry as IGeometryCollection };
145129
default:
146130
return null;
147131
}
148132
}
149133

150134
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) =>
151135
throw new NotSupportedException();
152-
153-
private static TShape SetIgnoreUnmapped<TShape>(TShape shape, bool? ignoreUnmapped) where TShape : IGeoShape
154-
{
155-
if (shape != null)
156-
shape.IgnoreUnmapped = ignoreUnmapped;
157-
return shape;
158-
}
159136
}
160137
}

src/Nest/QueryDsl/Geo/Shape/GeometryCollection/GeometryCollection.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using Newtonsoft.Json;
34

45
namespace Nest
@@ -33,6 +34,7 @@ public class GeometryCollection : IGeometryCollection, IGeoShape
3334
string IGeoShape.Type => this.Type;
3435

3536
/// <inheritdoc />
37+
[Obsolete("Removed in NEST 7.x. Use IgnoreUnmapped on IGeoShapeQuery")]
3638
public bool? IgnoreUnmapped { get; set; }
3739

3840
/// <inheritdoc />

src/Nest/QueryDsl/Geo/Shape/IGeoShapeQuery.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,21 @@ public interface IGeoShapeQuery : IFieldNameQuery
1212
[JsonProperty("relation")]
1313
GeoShapeRelation? Relation { get; set; }
1414

15+
/// <summary>
16+
/// Will ignore an unmapped field and will not match any documents for this query.
17+
/// This can be useful when querying multiple indexes which might have different mappings.
18+
/// </summary>
19+
[JsonProperty("ignore_unmapped")]
20+
bool? IgnoreUnmapped { get; set; }
1521
}
1622

1723
public abstract class GeoShapeQueryBase : FieldNameQueryBase, IGeoShapeQuery
1824
{
19-
/// <summary>
20-
/// Controls the spatial relation operator to use at search time.
21-
/// </summary>
25+
/// <inheritdoc />
2226
public GeoShapeRelation? Relation { get; set; }
2327

28+
/// <inheritdoc />
29+
public bool? IgnoreUnmapped { get; set; }
2430
}
2531

2632
public abstract class GeoShapeQueryDescriptorBase<TDescriptor, TInterface, T>
@@ -30,16 +36,12 @@ public abstract class GeoShapeQueryDescriptorBase<TDescriptor, TInterface, T>
3036
where T : class
3137
{
3238
GeoShapeRelation? IGeoShapeQuery.Relation { get; set; }
39+
bool? IGeoShapeQuery.IgnoreUnmapped { get; set; }
3340

34-
/// <summary>
35-
/// Controls the spatial relation operator to used at search time.
36-
/// </summary>
41+
/// <inheritdoc cref="IGeoShapeQuery.Relation"/>
3742
public TDescriptor Relation(GeoShapeRelation? relation) => Assign(a => a.Relation = relation);
3843

39-
// /// <summary>
40-
// /// Will ignore an unmapped field and will not match any documents for this query.
41-
// /// This can be useful when querying multiple indexes which might have different mappings.
42-
// /// </summary>
43-
// public TDescriptor IgnoreUnmapped(bool? ignoreUnmapped = true) => Assign(a => a.IgnoreUnmapped = ignoreUnmapped);
44+
/// <inheritdoc cref="IGeoShapeQuery.IgnoreUnmapped"/>
45+
public TDescriptor IgnoreUnmapped(bool? ignoreUnmapped = true) => Assign(a => a.IgnoreUnmapped = ignoreUnmapped);
4446
}
4547
}

src/Nest/QueryDsl/Geo/Shape/LineString/GeoShapeLineStringQuery.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,24 @@ public interface IGeoShapeLineStringQuery : IGeoShapeQuery
1212

1313
public class GeoShapeLineStringQuery : GeoShapeQueryBase, IGeoShapeLineStringQuery
1414
{
15+
private ILineStringGeoShape _shape;
1516
protected override bool Conditionless => IsConditionless(this);
16-
public ILineStringGeoShape Shape { get; set; }
17+
18+
public ILineStringGeoShape Shape
19+
{
20+
get => _shape;
21+
set
22+
{
23+
#pragma warning disable 618
24+
if (value?.IgnoreUnmapped != null)
25+
{
26+
IgnoreUnmapped = value.IgnoreUnmapped;
27+
value.IgnoreUnmapped = null;
28+
}
29+
#pragma warning restore 618
30+
_shape = value;
31+
}
32+
}
1733

1834
internal override void InternalWrapInContainer(IQueryContainer c) => c.GeoShape = this;
1935
internal static bool IsConditionless(IGeoShapeLineStringQuery q) => q.Field.IsConditionless() || q.Shape == null || !q.Shape.Coordinates.HasAny();
@@ -30,7 +46,7 @@ public GeoShapeLineStringQueryDescriptor<T> Coordinates(IEnumerable<GeoCoordinat
3046
{
3147
a.Shape = a.Shape ?? new LineStringGeoShape();
3248
a.Shape.Coordinates = coordinates;
33-
a.Shape.IgnoreUnmapped = ignoreUnmapped;
49+
a.IgnoreUnmapped = ignoreUnmapped;
3450
});
3551
}
3652
}

src/Nest/QueryDsl/Geo/Shape/MultiLineString/GeoShapeMultiLineStringQuery.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,24 @@ public interface IGeoShapeMultiLineStringQuery : IGeoShapeQuery
1212

1313
public class GeoShapeMultiLineStringQuery : GeoShapeQueryBase, IGeoShapeMultiLineStringQuery
1414
{
15+
private IMultiLineStringGeoShape _shape;
1516
protected override bool Conditionless => IsConditionless(this);
16-
public IMultiLineStringGeoShape Shape { get; set; }
17+
18+
public IMultiLineStringGeoShape Shape
19+
{
20+
get => _shape;
21+
set
22+
{
23+
#pragma warning disable 618
24+
if (value?.IgnoreUnmapped != null)
25+
{
26+
IgnoreUnmapped = value.IgnoreUnmapped;
27+
value.IgnoreUnmapped = null;
28+
}
29+
#pragma warning restore 618
30+
_shape = value;
31+
}
32+
}
1733

1834
internal override void InternalWrapInContainer(IQueryContainer c) => c.GeoShape = this;
1935
internal static bool IsConditionless(IGeoShapeMultiLineStringQuery q) => q.Field.IsConditionless() || q.Shape == null || !q.Shape.Coordinates.HasAny();
@@ -30,7 +46,7 @@ public GeoShapeMultiLineStringQueryDescriptor<T> Coordinates(IEnumerable<IEnumer
3046
{
3147
a.Shape = a.Shape ?? new MultiLineStringGeoShape();
3248
a.Shape.Coordinates = coordinates;
33-
a.Shape.IgnoreUnmapped = ignoreUnmapped;
49+
a.IgnoreUnmapped = ignoreUnmapped;
3450
});
3551
}
3652
}

0 commit comments

Comments
 (0)