Skip to content

Commit 4125cf9

Browse files
authored
Support deprecated range query properties (#6042)
* Initial work to support deprecated properties * Support additional deprecated properties on range query * Allow skipping some checks in code standards
1 parent 9b7076d commit 4125cf9

File tree

10 files changed

+342
-42
lines changed

10 files changed

+342
-42
lines changed

src/Elasticsearch.Net/Extensions/ArraySegmentBytesExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static bool IsDateTime(this ref ArraySegment<byte> arraySegment, IJsonFor
103103
dateTime = default;
104104

105105
// TODO: Nicer way to do this
106-
var reader = new JsonReader(arraySegment.Array, arraySegment.Offset - 1); // include opening quote "
106+
var reader = new JsonReader(arraySegment.Array, arraySegment.Offset > 0 ? arraySegment.Offset - 1: arraySegment.Offset); // try to include opening quote "
107107
try
108108
{
109109
dateTime = ISO8601DateTimeFormatter.Default.Deserialize(ref reader, formatterResolver);

src/Nest/QueryDsl/TermLevel/Range/DateRangeQuery.cs

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5+
using System;
56
using System.Runtime.Serialization;
67
using Elasticsearch.Net.Utf8Json;
78

@@ -31,18 +32,67 @@ public interface IDateRangeQuery : IRangeQuery
3132

3233
[DataMember(Name = "time_zone")]
3334
string TimeZone { get; set; }
35+
36+
/// <summary>
37+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
38+
/// </summary>
39+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
40+
[DataMember(Name = "from")]
41+
DateMath From { get; set; }
42+
43+
/// <summary>
44+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
45+
/// </summary>
46+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
47+
[DataMember(Name = "to")]
48+
DateMath To { get; set; }
49+
50+
/// <summary>
51+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
52+
/// </summary>
53+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
54+
[DataMember(Name = "include_lower")]
55+
bool? IncludeLower { get; set; }
56+
57+
/// <summary>
58+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
59+
/// </summary>
60+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
61+
[DataMember(Name = "include_upper")]
62+
bool? IncludeUpper { get; set; }
3463
}
3564

3665
public class DateRangeQuery : FieldNameQueryBase, IDateRangeQuery
3766
{
3867
public string Format { get; set; }
3968
public DateMath GreaterThan { get; set; }
40-
4169
public DateMath GreaterThanOrEqualTo { get; set; }
4270
public DateMath LessThan { get; set; }
4371
public DateMath LessThanOrEqualTo { get; set; }
4472
public RangeRelation? Relation { get; set; }
4573
public string TimeZone { get; set; }
74+
75+
/// <summary>
76+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
77+
/// </summary>
78+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
79+
public DateMath From { get; set; }
80+
/// <summary>
81+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
82+
/// </summary>
83+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
84+
public DateMath To { get; set; }
85+
/// <summary>
86+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
87+
/// </summary>
88+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
89+
public bool? IncludeLower { get; set; }
90+
/// <summary>
91+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
92+
/// </summary>
93+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
94+
public bool? IncludeUpper { get; set; }
95+
4696
protected override bool Conditionless => IsConditionless(this);
4797

4898
internal override void InternalWrapInContainer(IQueryContainer c) => c.Range = this;
@@ -51,13 +101,16 @@ internal static bool IsConditionless(IDateRangeQuery q) => q.Field.IsConditionle
51101
|| ((q.GreaterThanOrEqualTo == null || !q.GreaterThanOrEqualTo.IsValid)
52102
&& (q.LessThanOrEqualTo == null || !q.LessThanOrEqualTo.IsValid)
53103
&& (q.GreaterThan == null || !q.GreaterThan.IsValid)
54-
&& (q.LessThan == null || !q.LessThan.IsValid));
104+
&& (q.LessThan == null || !q.LessThan.IsValid)
105+
#pragma warning disable CS0618 // Type or member is obsolete
106+
&& (q.From == null || !q.From.IsValid)
107+
&& (q.To == null || !q.To.IsValid));
108+
#pragma warning restore CS0618 // Type or member is obsolete
55109
}
56110

57111
[DataContract]
58112
public class DateRangeQueryDescriptor<T>
59-
: FieldNameQueryDescriptorBase<DateRangeQueryDescriptor<T>, IDateRangeQuery, T>
60-
, IDateRangeQuery where T : class
113+
: FieldNameQueryDescriptorBase<DateRangeQueryDescriptor<T>, IDateRangeQuery, T>, IDateRangeQuery where T : class
61114
{
62115
protected override bool Conditionless => DateRangeQuery.IsConditionless(this);
63116
string IDateRangeQuery.Format { get; set; }
@@ -68,18 +121,18 @@ public class DateRangeQueryDescriptor<T>
68121
RangeRelation? IDateRangeQuery.Relation { get; set; }
69122
string IDateRangeQuery.TimeZone { get; set; }
70123

71-
public DateRangeQueryDescriptor<T> GreaterThan(DateMath from) => Assign(from, (a, v) => a.GreaterThan = v);
124+
// From, To, IncludeLower and IncludeUpper are not exposed as methods as they are considered deprecated and legacy.
125+
DateMath IDateRangeQuery.From { get; set; }
126+
DateMath IDateRangeQuery.To { get; set; }
127+
bool? IDateRangeQuery.IncludeLower { get; set; }
128+
bool? IDateRangeQuery.IncludeUpper { get; set; }
72129

130+
public DateRangeQueryDescriptor<T> GreaterThan(DateMath from) => Assign(from, (a, v) => a.GreaterThan = v);
73131
public DateRangeQueryDescriptor<T> GreaterThanOrEquals(DateMath from) => Assign(from, (a, v) => a.GreaterThanOrEqualTo = v);
74-
75132
public DateRangeQueryDescriptor<T> LessThan(DateMath to) => Assign(to, (a, v) => a.LessThan = v);
76-
77133
public DateRangeQueryDescriptor<T> LessThanOrEquals(DateMath to) => Assign(to, (a, v) => a.LessThanOrEqualTo = v);
78-
79134
public DateRangeQueryDescriptor<T> TimeZone(string timeZone) => Assign(timeZone, (a, v) => a.TimeZone = v);
80-
81135
public DateRangeQueryDescriptor<T> Format(string format) => Assign(format, (a, v) => a.Format = v);
82-
83136
public DateRangeQueryDescriptor<T> Relation(RangeRelation? relation) => Assign(relation, (a, v) => a.Relation = v);
84137
}
85138
}

src/Nest/QueryDsl/TermLevel/Range/LongRangeQuery.cs

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5+
using System;
56
using System.Runtime.Serialization;
67
using Elasticsearch.Net.Utf8Json;
78

@@ -23,8 +24,33 @@ public interface ILongRangeQuery : IRangeQuery
2324
[DataMember(Name ="lte")]
2425
long? LessThanOrEqualTo { get; set; }
2526

26-
[DataMember(Name ="relation")]
27+
[DataMember(Name = "relation")]
2728
RangeRelation? Relation { get; set; }
29+
30+
/// <summary>
31+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
32+
/// </summary>
33+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
34+
[DataMember(Name = "from")]
35+
long? From { get; set; }
36+
/// <summary>
37+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
38+
/// </summary>
39+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
40+
[DataMember(Name = "to")]
41+
long? To { get; set; }
42+
/// <summary>
43+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
44+
/// </summary>
45+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
46+
[DataMember(Name = "include_lower")]
47+
bool? IncludeLower { get; set; }
48+
/// <summary>
49+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
50+
/// </summary>
51+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
52+
[DataMember(Name = "include_upper")]
53+
bool? IncludeUpper { get; set; }
2854
}
2955

3056
public class LongRangeQuery : FieldNameQueryBase, ILongRangeQuery
@@ -34,6 +60,27 @@ public class LongRangeQuery : FieldNameQueryBase, ILongRangeQuery
3460
public long? LessThan { get; set; }
3561
public long? LessThanOrEqualTo { get; set; }
3662

63+
/// <summary>
64+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
65+
/// </summary>
66+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
67+
public long? From { get; set; }
68+
/// <summary>
69+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
70+
/// </summary>
71+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
72+
public long? To { get; set; }
73+
/// <summary>
74+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
75+
/// </summary>
76+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
77+
public bool? IncludeLower { get; set; }
78+
/// <summary>
79+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
80+
/// </summary>
81+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
82+
public bool? IncludeUpper { get; set; }
83+
3784
public RangeRelation? Relation { get; set; }
3885
protected override bool Conditionless => IsConditionless(this);
3986

@@ -43,13 +90,16 @@ internal static bool IsConditionless(ILongRangeQuery q) => q.Field.IsConditionle
4390
|| q.GreaterThanOrEqualTo == null
4491
&& q.LessThanOrEqualTo == null
4592
&& q.GreaterThan == null
46-
&& q.LessThan == null;
93+
&& q.LessThan == null
94+
#pragma warning disable CS0618 // Type or member is obsolete
95+
&& q.From == null
96+
&& q.To == null;
97+
#pragma warning restore CS0618 // Type or member is obsolete
4798
}
4899

49100
[DataContract]
50101
public class LongRangeQueryDescriptor<T>
51-
: FieldNameQueryDescriptorBase<LongRangeQueryDescriptor<T>, ILongRangeQuery, T>
52-
, ILongRangeQuery where T : class
102+
: FieldNameQueryDescriptorBase<LongRangeQueryDescriptor<T>, ILongRangeQuery, T>, ILongRangeQuery where T : class
53103
{
54104
protected override bool Conditionless => LongRangeQuery.IsConditionless(this);
55105
long? ILongRangeQuery.GreaterThan { get; set; }
@@ -58,14 +108,16 @@ public class LongRangeQueryDescriptor<T>
58108
long? ILongRangeQuery.LessThanOrEqualTo { get; set; }
59109
RangeRelation? ILongRangeQuery.Relation { get; set; }
60110

61-
public LongRangeQueryDescriptor<T> Relation(RangeRelation? relation) => Assign(relation, (a, v) => a.Relation = v);
111+
// From, To, IncludeLower and IncludeUpper are not exposed as methods as they are considered deprecated and legacy.
112+
long? ILongRangeQuery.From { get; set; }
113+
long? ILongRangeQuery.To { get; set; }
114+
bool? ILongRangeQuery.IncludeLower { get; set; }
115+
bool? ILongRangeQuery.IncludeUpper { get; set; }
62116

117+
public LongRangeQueryDescriptor<T> Relation(RangeRelation? relation) => Assign(relation, (a, v) => a.Relation = v);
63118
public LongRangeQueryDescriptor<T> GreaterThan(long? from) => Assign(from, (a, v) => a.GreaterThan = v);
64-
65119
public LongRangeQueryDescriptor<T> GreaterThanOrEquals(long? from) => Assign(from, (a, v) => a.GreaterThanOrEqualTo = v);
66-
67120
public LongRangeQueryDescriptor<T> LessThan(long? to) => Assign(to, (a, v) => a.LessThan = v);
68-
69121
public LongRangeQueryDescriptor<T> LessThanOrEquals(long? to) => Assign(to, (a, v) => a.LessThanOrEqualTo = v);
70122
}
71123
}

src/Nest/QueryDsl/TermLevel/Range/NumericRangeQuery.cs

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5+
using System;
56
using System.Runtime.Serialization;
67
using Elasticsearch.Net.Utf8Json;
78

@@ -25,6 +26,34 @@ public interface INumericRangeQuery : IRangeQuery
2526

2627
[DataMember(Name = "relation")]
2728
RangeRelation? Relation { get; set; }
29+
30+
/// <summary>
31+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
32+
/// </summary>
33+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
34+
[DataMember(Name = "from")]
35+
double? From { get; set; }
36+
37+
/// <summary>
38+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
39+
/// </summary>
40+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
41+
[DataMember(Name = "to")]
42+
double? To { get; set; }
43+
44+
/// <summary>
45+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
46+
/// </summary>
47+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
48+
[DataMember(Name = "include_lower")]
49+
bool? IncludeLower { get; set; }
50+
51+
/// <summary>
52+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
53+
/// </summary>
54+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
55+
[DataMember(Name = "include_upper")]
56+
bool? IncludeUpper { get; set; }
2857
}
2958

3059
public class NumericRangeQuery : FieldNameQueryBase, INumericRangeQuery
@@ -33,8 +62,29 @@ public class NumericRangeQuery : FieldNameQueryBase, INumericRangeQuery
3362
public double? GreaterThanOrEqualTo { get; set; }
3463
public double? LessThan { get; set; }
3564
public double? LessThanOrEqualTo { get; set; }
36-
3765
public RangeRelation? Relation { get; set; }
66+
67+
/// <summary>
68+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
69+
/// </summary>
70+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
71+
public double? From { get; set; }
72+
/// <summary>
73+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
74+
/// </summary>
75+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
76+
public double? To { get; set; }
77+
/// <summary>
78+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
79+
/// </summary>
80+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
81+
public bool? IncludeLower { get; set; }
82+
/// <summary>
83+
/// WARNING: This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.
84+
/// </summary>
85+
[Obsolete("This property is considered deprecated and will be removed in the next major release. Range queries should prefer the gt, lt, gte and lte properties instead.")]
86+
public bool? IncludeUpper { get; set; }
87+
3888
protected override bool Conditionless => IsConditionless(this);
3989

4090
internal override void InternalWrapInContainer(IQueryContainer c) => c.Range = this;
@@ -43,30 +93,35 @@ internal static bool IsConditionless(INumericRangeQuery q) => q.Field.IsConditio
4393
|| q.GreaterThanOrEqualTo == null
4494
&& q.LessThanOrEqualTo == null
4595
&& q.GreaterThan == null
46-
&& q.LessThan == null;
96+
&& q.LessThan == null
97+
#pragma warning disable CS0618 // Type or member is obsolete
98+
&& q.From == null
99+
&& q.To == null;
100+
#pragma warning restore CS0618 // Type or member is obsolete
47101
}
48102

49103
[DataContract]
50104
public class NumericRangeQueryDescriptor<T>
51-
: FieldNameQueryDescriptorBase<NumericRangeQueryDescriptor<T>, INumericRangeQuery, T>
52-
, INumericRangeQuery where T : class
105+
: FieldNameQueryDescriptorBase<NumericRangeQueryDescriptor<T>, INumericRangeQuery, T>, INumericRangeQuery where T : class
53106
{
54107
protected override bool Conditionless => NumericRangeQuery.IsConditionless(this);
108+
55109
double? INumericRangeQuery.GreaterThan { get; set; }
56110
double? INumericRangeQuery.GreaterThanOrEqualTo { get; set; }
57111
double? INumericRangeQuery.LessThan { get; set; }
58112
double? INumericRangeQuery.LessThanOrEqualTo { get; set; }
59-
60113
RangeRelation? INumericRangeQuery.Relation { get; set; }
61114

62-
public NumericRangeQueryDescriptor<T> GreaterThan(double? from) => Assign(from, (a, v) => a.GreaterThan = v);
115+
// From, To, IncludeLower and IncludeUpper are not exposed as methods as they are considered deprecated and legacy.
116+
double? INumericRangeQuery.From { get; set; }
117+
double? INumericRangeQuery.To { get; set; }
118+
bool? INumericRangeQuery.IncludeLower { get; set; }
119+
bool? INumericRangeQuery.IncludeUpper { get; set; }
63120

121+
public NumericRangeQueryDescriptor<T> GreaterThan(double? from) => Assign(from, (a, v) => a.GreaterThan = v);
64122
public NumericRangeQueryDescriptor<T> GreaterThanOrEquals(double? from) => Assign(from, (a, v) => a.GreaterThanOrEqualTo = v);
65-
66123
public NumericRangeQueryDescriptor<T> LessThan(double? to) => Assign(to, (a, v) => a.LessThan = v);
67-
68124
public NumericRangeQueryDescriptor<T> LessThanOrEquals(double? to) => Assign(to, (a, v) => a.LessThanOrEqualTo = v);
69-
70125
public NumericRangeQueryDescriptor<T> Relation(RangeRelation? relation) => Assign(relation, (a, v) => a.Relation = v);
71126
}
72127
}

0 commit comments

Comments
 (0)