Skip to content

Commit 321868a

Browse files
committed
Deprecate coerce and ignore_malformed on geo_polygon, geo_distance, geo_distance_range and geo_bounding_box queries
Ensure all nullable boolean properties on IQuery types accept a nullable bool with a default value to the descriptor method
1 parent e36cad4 commit 321868a

File tree

20 files changed

+176
-78
lines changed

20 files changed

+176
-78
lines changed

src/Nest/CommonAbstractions/SerializationBehavior/JsonNetSerializer.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected virtual void ModifyJsonSerializerSettings(JsonSerializerSettings setti
3030
public JsonNetSerializer(IConnectionSettingsValues settings) : this(settings, null) { }
3131

3232
/// <summary>
33-
/// this constructor is only here for stateful (de)serialization
33+
/// this constructor is only here for stateful (de)serialization
3434
/// </summary>
3535
internal JsonNetSerializer(IConnectionSettingsValues settings, JsonConverter stateFullConverter)
3636
{
@@ -40,9 +40,7 @@ internal JsonNetSerializer(IConnectionSettingsValues settings, JsonConverter sta
4040
this.ContractResolver = new ElasticContractResolver(this.Settings, this.ContractConverters) { PiggyBackState = piggyBackState };
4141

4242
this._defaultSerializer = JsonSerializer.Create(this.CreateSettings(SerializationFormatting.None));
43-
//this._defaultSerializer.Formatting = Formatting.None;
4443
var indentedSerializer = JsonSerializer.Create(this.CreateSettings(SerializationFormatting.Indented));
45-
//indentedSerializer.Formatting = Formatting.Indented;
4644
this._defaultSerializers = new Dictionary<SerializationFormatting, JsonSerializer>
4745
{
4846
{ SerializationFormatting.None, this._defaultSerializer },
@@ -117,4 +115,4 @@ private JsonSerializerSettings CreateSettings(SerializationFormatting formatting
117115
return settings;
118116
}
119117
}
120-
}
118+
}

src/Nest/QueryDsl/Compound/Bool/BoolQuery.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public class BoolQuery : QueryBase, IBoolQuery
9595
internal override void InternalWrapInContainer(IQueryContainer c) => c.Bool = this;
9696

9797
protected override bool Conditionless => IsConditionless(this);
98+
9899
internal static bool IsConditionless(IBoolQuery q) =>
99100
q.Must.NotWritable() && q.MustNot.NotWritable() && q.Should.NotWritable() && q.Filter.NotWritable();
100101
}
@@ -120,7 +121,7 @@ public class BoolQueryDescriptor<T>
120121
/// the greater the chances that the document is a good match for the query.
121122
/// </summary>
122123
/// <returns></returns>
123-
public BoolQueryDescriptor<T> DisableCoord() => Assign(a => a.DisableCoord = true);
124+
public BoolQueryDescriptor<T> DisableCoord(bool? disableCoord = true) => Assign(a => a.DisableCoord = disableCoord);
124125

125126
/// <summary>
126127
/// Specifies a minimum number of the optional BooleanClauses which must be satisfied.

src/Nest/QueryDsl/FullText/MultiMatch/MultiMatchQuery.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ public MultiMatchQueryDescriptor<T> MinimumShouldMatch(MinimumShouldMatch minimu
160160

161161
public MultiMatchQueryDescriptor<T> Type(TextQueryType? type) => Assign(a => a.Type = type);
162162

163+
public MultiMatchQueryDescriptor<T> UseDisMax(bool? useDisMax = true) => Assign(a => a.UseDisMax = useDisMax);
164+
163165
public MultiMatchQueryDescriptor<T> ZeroTermsQuery(ZeroTermsQuery? zeroTermsQuery) => Assign(a => a.ZeroTermsQuery = zeroTermsQuery);
164166
}
165167
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ public interface IGeoBoundingBoxQuery : IFieldNameQuery
1313
[JsonProperty("type")]
1414
GeoExecution? Type { get; set; }
1515

16+
[Obsolete("Deprecated. Use ValidationMethod")]
1617
[JsonProperty("coerce")]
1718
bool? Coerce { get; set; }
1819

20+
[Obsolete("Deprecated. Use ValidationMethod")]
1921
[JsonProperty("ignore_malformed")]
2022
bool? IgnoreMalformed { get; set; }
2123

@@ -29,7 +31,11 @@ public class GeoBoundingBoxQuery : FieldNameQueryBase, IGeoBoundingBoxQuery
2931
protected override bool Conditionless => IsConditionless(this);
3032
public IBoundingBox BoundingBox { get; set; }
3133
public GeoExecution? Type { get; set; }
34+
35+
[Obsolete("Deprecated. Use ValidationMethod")]
3236
public bool? Coerce { get; set; }
37+
38+
[Obsolete("Deprecated. Use ValidationMethod")]
3339
public bool? IgnoreMalformed { get; set; }
3440
public GeoValidationMethod? ValidationMethod { get; set; }
3541

@@ -50,19 +56,21 @@ public class GeoBoundingBoxQueryDescriptor<T>
5056
bool? IGeoBoundingBoxQuery.IgnoreMalformed { get; set; }
5157
GeoValidationMethod? IGeoBoundingBoxQuery.ValidationMethod { get; set; }
5258

53-
public GeoBoundingBoxQueryDescriptor<T> BoundingBox(double topLeftLat, double topLeftLon, double bottomRightLat, double bottomRightLon) =>
59+
public GeoBoundingBoxQueryDescriptor<T> BoundingBox(double topLeftLat, double topLeftLon, double bottomRightLat, double bottomRightLon) =>
5460
BoundingBox(f=>f.TopLeft(topLeftLat, topLeftLon).BottomRight(bottomRightLat, bottomRightLon));
5561

56-
public GeoBoundingBoxQueryDescriptor<T> BoundingBox(GeoLocation topLeft, GeoLocation bottomRight) =>
62+
public GeoBoundingBoxQueryDescriptor<T> BoundingBox(GeoLocation topLeft, GeoLocation bottomRight) =>
5763
BoundingBox(f=>f.TopLeft(topLeft).BottomRight(bottomRight));
5864

59-
public GeoBoundingBoxQueryDescriptor<T> BoundingBox(Func<BoundingBoxDescriptor, IBoundingBox> boundingBoxSelector) =>
65+
public GeoBoundingBoxQueryDescriptor<T> BoundingBox(Func<BoundingBoxDescriptor, IBoundingBox> boundingBoxSelector) =>
6066
Assign(a => a.BoundingBox = boundingBoxSelector?.Invoke(new BoundingBoxDescriptor()));
6167

6268
public GeoBoundingBoxQueryDescriptor<T> Type(GeoExecution type) => Assign(a => a.Type = type);
6369

70+
[Obsolete("Deprecated. Use ValidationMethod(GeoValidationMethod? validation)")]
6471
public GeoBoundingBoxQueryDescriptor<T> Coerce(bool? coerce = true) => Assign(a => a.Coerce = coerce);
6572

73+
[Obsolete("Deprecated. Use ValidationMethod(GeoValidationMethod? validation)")]
6674
public GeoBoundingBoxQueryDescriptor<T> IgnoreMalformed(bool? ignore = true) => Assign(a => a.IgnoreMalformed = ignore);
6775

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

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Newtonsoft.Json;
1+
using System;
2+
using Newtonsoft.Json;
23

34
namespace Nest
45
{
@@ -8,25 +9,27 @@ public interface IGeoDistanceQuery : IFieldNameQuery
89
{
910
[VariableField]
1011
GeoLocation Location { get; set; }
11-
12+
1213
[JsonProperty("distance")]
1314
Distance Distance { get; set; }
14-
15+
1516
[JsonProperty("optimize_bbox")]
1617
GeoOptimizeBBox? OptimizeBoundingBox { get; set; }
1718

1819
[JsonProperty("distance_type")]
1920
GeoDistanceType? DistanceType { get; set; }
2021

22+
[Obsolete("Deprecated. Use ValidationMethod")]
2123
[JsonProperty("coerce")]
2224
bool? Coerce { get; set; }
2325

26+
[Obsolete("Deprecated. Use ValidationMethod")]
2427
[JsonProperty("ignore_malformed")]
2528
bool? IgnoreMalformed { get; set; }
26-
29+
2730
[JsonProperty("validation_method")]
2831
GeoValidationMethod? ValidationMethod { get; set; }
29-
32+
3033
}
3134

3235
public class GeoDistanceQuery : FieldNameQueryBase, IGeoDistanceQuery
@@ -36,19 +39,23 @@ public class GeoDistanceQuery : FieldNameQueryBase, IGeoDistanceQuery
3639
public Distance Distance { get; set; }
3740
public GeoOptimizeBBox? OptimizeBoundingBox { get; set; }
3841
public GeoDistanceType? DistanceType { get; set; }
42+
43+
[Obsolete("Deprecated. Use ValidationMethod")]
3944
public bool? Coerce { get; set; }
45+
46+
[Obsolete("Deprecated. Use ValidationMethod")]
4047
public bool? IgnoreMalformed { get; set; }
41-
public GeoValidationMethod? ValidationMethod { get; set; }
4248

49+
public GeoValidationMethod? ValidationMethod { get; set; }
4350

4451
internal override void InternalWrapInContainer(IQueryContainer c) => c.GeoDistance = this;
4552

46-
internal static bool IsConditionless(IGeoDistanceQuery q) =>
53+
internal static bool IsConditionless(IGeoDistanceQuery q) =>
4754
q.Location == null || q.Distance == null || q.Field.IsConditionless();
4855
}
4956

50-
public class GeoDistanceQueryDescriptor<T>
51-
: FieldNameQueryDescriptorBase<GeoDistanceQueryDescriptor<T>, IGeoDistanceQuery, T>
57+
public class GeoDistanceQueryDescriptor<T>
58+
: FieldNameQueryDescriptorBase<GeoDistanceQueryDescriptor<T>, IGeoDistanceQuery, T>
5259
, IGeoDistanceQuery where T : class
5360
{
5461
protected override bool Conditionless => GeoDistanceQuery.IsConditionless(this);
@@ -72,8 +79,10 @@ public class GeoDistanceQueryDescriptor<T>
7279

7380
public GeoDistanceQueryDescriptor<T> DistanceType(GeoDistanceType type) => Assign(a => a.DistanceType = type);
7481

82+
[Obsolete("Deprecated. Use ValidationMethod(GeoValidationMethod? validation)")]
7583
public GeoDistanceQueryDescriptor<T> Coerce(bool? coerce = true) => Assign(a => a.Coerce = coerce);
7684

85+
[Obsolete("Deprecated. Use ValidationMethod(GeoValidationMethod? validation)")]
7786
public GeoDistanceQueryDescriptor<T> IgnoreMalformed(bool? ignore = true) => Assign(a => a.IgnoreMalformed = ignore);
7887

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

src/Nest/QueryDsl/Geo/DistanceRange/GeoDistanceRangeQuery.cs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Newtonsoft.Json;
1+
using System;
2+
using Newtonsoft.Json;
23

34
namespace Nest
45
{
@@ -11,10 +12,10 @@ public interface IGeoDistanceRangeQuery : IFieldNameQuery
1112

1213
[JsonProperty("gte")]
1314
Distance GreaterThanOrEqualTo { get; set; }
14-
15+
1516
[JsonProperty("lte")]
1617
Distance LessThanOrEqualTo { get; set; }
17-
18+
1819
[JsonProperty("gt")]
1920
Distance GreaterThan { get; set; }
2021

@@ -23,19 +24,21 @@ public interface IGeoDistanceRangeQuery : IFieldNameQuery
2324

2425
[JsonProperty("distance_type")]
2526
GeoDistanceType? DistanceType { get; set; }
26-
27+
2728
[JsonProperty("optimize_bbox")]
2829
GeoOptimizeBBox? OptimizeBoundingBox { get; set; }
29-
30+
31+
[Obsolete("Deprecated. Use ValidationMethod")]
3032
[JsonProperty("coerce")]
3133
bool? Coerce { get; set; }
3234

35+
[Obsolete("Deprecated. Use ValidationMethod")]
3336
[JsonProperty("ignore_malformed")]
3437
bool? IgnoreMalformed { get; set; }
35-
38+
3639
[JsonProperty("validation_method")]
3740
GeoValidationMethod? ValidationMethod { get; set; }
38-
41+
3942
}
4043

4144
public class GeoDistanceRangeQuery : FieldNameQueryBase, IGeoDistanceRangeQuery
@@ -48,18 +51,22 @@ public class GeoDistanceRangeQuery : FieldNameQueryBase, IGeoDistanceRangeQuery
4851
public Distance LessThanOrEqualTo { get; set; }
4952
public GeoDistanceType? DistanceType { get; set; }
5053
public GeoOptimizeBBox? OptimizeBoundingBox { get; set; }
54+
55+
[Obsolete("Deprecated. Use ValidationMethod")]
5156
public bool? Coerce { get; set; }
57+
58+
[Obsolete("Deprecated. Use ValidationMethod")]
5259
public bool? IgnoreMalformed { get; set; }
5360
public GeoValidationMethod? ValidationMethod { get; set; }
5461

5562
internal override void InternalWrapInContainer(IQueryContainer c) => c.GeoDistanceRange = this;
5663

57-
internal static bool IsConditionless(IGeoDistanceRangeQuery q) =>
58-
q.Field == null || q.Location == null
64+
internal static bool IsConditionless(IGeoDistanceRangeQuery q) =>
65+
q.Field == null || q.Location == null
5966
|| (q.LessThan == null && q.LessThanOrEqualTo == null && q.GreaterThanOrEqualTo == null && q.GreaterThan == null);
6067
}
6168

62-
public class GeoDistanceRangeQueryDescriptor<T> : FieldNameQueryDescriptorBase<GeoDistanceRangeQueryDescriptor<T>, IGeoDistanceRangeQuery, T>
69+
public class GeoDistanceRangeQueryDescriptor<T> : FieldNameQueryDescriptorBase<GeoDistanceRangeQueryDescriptor<T>, IGeoDistanceRangeQuery, T>
6370
, IGeoDistanceRangeQuery where T : class
6471
{
6572
protected override bool Conditionless => GeoDistanceRangeQuery.IsConditionless(this);
@@ -86,20 +93,21 @@ public GeoDistanceRangeQueryDescriptor<T> GreaterThanOrEqualTo(double distance,
8693
Assign(a => a.GreaterThanOrEqualTo = new Distance(distance, unit));
8794

8895
public GeoDistanceRangeQueryDescriptor<T> LessThanOrEqualTo(Distance to) => Assign(a => a.LessThanOrEqualTo = to);
89-
public GeoDistanceRangeQueryDescriptor<T> LessThanOrEqualTo(double distance, DistanceUnit unit) =>
96+
public GeoDistanceRangeQueryDescriptor<T> LessThanOrEqualTo(double distance, DistanceUnit unit) =>
9097
Assign(a => a.LessThanOrEqualTo = new Distance(distance, unit));
9198

9299
public GeoDistanceRangeQueryDescriptor<T> LessThan(Distance to) => Assign(a => a.LessThan = to);
93-
public GeoDistanceRangeQueryDescriptor<T> LessThan(double distance, DistanceUnit unit) =>
100+
public GeoDistanceRangeQueryDescriptor<T> LessThan(double distance, DistanceUnit unit) =>
94101
Assign(a => a.LessThan = new Distance(distance, unit));
95102

96103
public GeoDistanceRangeQueryDescriptor<T> Optimize(GeoOptimizeBBox optimize) => Assign(a => a.OptimizeBoundingBox = optimize);
97104

98105
public GeoDistanceRangeQueryDescriptor<T> DistanceType(GeoDistanceType geoDistance) => Assign(a => a.DistanceType = geoDistance);
99106

100-
107+
[Obsolete("Deprecated. Use ValidationMethod(GeoValidationMethod? validation)")]
101108
public GeoDistanceRangeQueryDescriptor<T> Coerce(bool? coerce = true) => Assign(a => a.Coerce = coerce);
102109

110+
[Obsolete("Deprecated. Use ValidationMethod(GeoValidationMethod? validation)")]
103111
public GeoDistanceRangeQueryDescriptor<T> IgnoreMalformed(bool? ignore = true) => Assign(a => a.IgnoreMalformed = ignore);
104112

105113
public GeoDistanceRangeQueryDescriptor<T> ValidationMethod(GeoValidationMethod? validation) => Assign(a => a.ValidationMethod = validation);

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

Lines changed: 13 additions & 4 deletions
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
@@ -10,30 +11,36 @@ public interface IGeoPolygonQuery : IFieldNameQuery
1011
[VariableField("points")]
1112
IEnumerable<GeoLocation> Points { get; set; }
1213

14+
[Obsolete("Deprecated. Use ValidationMethod")]
1315
[JsonProperty("coerce")]
1416
bool? Coerce { get; set; }
1517

18+
[Obsolete("Deprecated. Use ValidationMethod")]
1619
[JsonProperty("ignore_malformed")]
1720
bool? IgnoreMalformed { get; set; }
18-
21+
1922
[JsonProperty("validation_method")]
2023
GeoValidationMethod? ValidationMethod { get; set; }
21-
24+
2225
}
2326

2427
public class GeoPolygonQuery : FieldNameQueryBase, IGeoPolygonQuery
2528
{
2629
protected override bool Conditionless => IsConditionless(this);
2730
public IEnumerable<GeoLocation> Points { get; set; }
31+
32+
[Obsolete("Deprecated. Use ValidationMethod")]
2833
public bool? Coerce { get; set; }
34+
35+
[Obsolete("Deprecated. Use ValidationMethod")]
2936
public bool? IgnoreMalformed { get; set; }
3037
public GeoValidationMethod? ValidationMethod { get; set; }
3138

3239
internal override void InternalWrapInContainer(IQueryContainer c) => c.GeoPolygon = this;
3340
internal static bool IsConditionless(IGeoPolygonQuery q) => q.Field == null || !q.Points.HasAny();
3441
}
3542

36-
public class GeoPolygonQueryDescriptor<T>
43+
public class GeoPolygonQueryDescriptor<T>
3744
: FieldNameQueryDescriptorBase<GeoPolygonQueryDescriptor<T>, IGeoPolygonQuery, T>
3845
, IGeoPolygonQuery where T : class
3946
{
@@ -47,8 +54,10 @@ public class GeoPolygonQueryDescriptor<T>
4754

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

57+
[Obsolete("Deprecated. Use ValidationMethod(GeoValidationMethod? validation)")]
5058
public GeoPolygonQueryDescriptor<T> Coerce(bool? coerce = true) => Assign(a => a.Coerce = coerce);
5159

60+
[Obsolete("Deprecated. Use ValidationMethod(GeoValidationMethod? validation)")]
5261
public GeoPolygonQueryDescriptor<T> IgnoreMalformed(bool? ignore = true) => Assign(a => a.IgnoreMalformed = ignore);
5362

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ public abstract class GeoShapeQueryDescriptorBase<TDescriptor, TInterface, T>
3535
/// Will ignore an unmapped field and will not match any documents for this query.
3636
/// This can be useful when querying multiple indexes which might have different mappings.
3737
/// </summary>
38-
public TDescriptor IgnoreUnmapped(bool ignoreUnmapped = false) => Assign(a => a.IgnoreUnmapped = ignoreUnmapped);
38+
public TDescriptor IgnoreUnmapped(bool? ignoreUnmapped = false) => Assign(a => a.IgnoreUnmapped = ignoreUnmapped);
3939
}
4040
}

src/Nest/QueryDsl/Joining/HasChild/HasChildQuery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public HasChildQueryDescriptor<T> Query(Func<QueryContainerDescriptor<T>, QueryC
9090
public HasChildQueryDescriptor<T> InnerHits(Func<InnerHitsDescriptor<T>, IInnerHits> selector = null) =>
9191
Assign(a => a.InnerHits = selector.InvokeOrDefault(new InnerHitsDescriptor<T>()));
9292

93-
public HasChildQueryDescriptor<T> IgnoreUnmapped(bool ignoreUnmapped = false) =>
93+
public HasChildQueryDescriptor<T> IgnoreUnmapped(bool? ignoreUnmapped = false) =>
9494
Assign(a => a.IgnoreUnmapped = ignoreUnmapped);
9595
}
9696
}

src/Nest/QueryDsl/Joining/HasParent/HasParentQuery.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ public HasParentQueryDescriptor<T> Query(Func<QueryContainerDescriptor<T>, Query
7272
/// Determines whether the score of the matching parent document is aggregated into the child documents belonging to the matching parent document.
7373
/// The default is false which ignores the score from the parent document.
7474
/// </summary>
75-
public HasParentQueryDescriptor<T> Score(bool score) => Assign(a => a.Score = score);
75+
public HasParentQueryDescriptor<T> Score(bool? score = false) => Assign(a => a.Score = score);
7676

7777
public HasParentQueryDescriptor<T> InnerHits(Func<InnerHitsDescriptor<T>, IInnerHits> selector = null) =>
7878
Assign(a => a.InnerHits = selector.InvokeOrDefault(new InnerHitsDescriptor<T>()));
7979

80-
public HasParentQueryDescriptor<T> IgnoreUnmapped(bool ignoreUnmapped = false) =>
80+
public HasParentQueryDescriptor<T> IgnoreUnmapped(bool? ignoreUnmapped = false) =>
8181
Assign(a => a.IgnoreUnmapped = ignoreUnmapped);
8282
}
8383
}

0 commit comments

Comments
 (0)