Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static bool IsDateTime(this ref ArraySegment<byte> arraySegment, IJsonFor
dateTime = default;

// TODO: Nicer way to do this
var reader = new JsonReader(arraySegment.Array, arraySegment.Offset - 1); // include opening quote "
var reader = new JsonReader(arraySegment.Array, arraySegment.Offset > 0 ? arraySegment.Offset - 1: arraySegment.Offset); // try to include opening quote "
try
{
dateTime = ISO8601DateTimeFormatter.Default.Deserialize(ref reader, formatterResolver);
Expand Down
73 changes: 63 additions & 10 deletions src/Nest/QueryDsl/TermLevel/Range/DateRangeQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System;
using System.Runtime.Serialization;
using Elasticsearch.Net.Utf8Json;

Expand Down Expand Up @@ -31,18 +32,67 @@ public interface IDateRangeQuery : IRangeQuery

[DataMember(Name = "time_zone")]
string TimeZone { get; set; }

/// <summary>
/// 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.
/// </summary>
[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.")]
[DataMember(Name = "from")]
DateMath From { get; set; }

/// <summary>
/// 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.
/// </summary>
[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.")]
[DataMember(Name = "to")]
DateMath To { get; set; }

/// <summary>
/// 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.
/// </summary>
[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.")]
[DataMember(Name = "include_lower")]
bool? IncludeLower { get; set; }

/// <summary>
/// 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.
/// </summary>
[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.")]
[DataMember(Name = "include_upper")]
bool? IncludeUpper { get; set; }
}

public class DateRangeQuery : FieldNameQueryBase, IDateRangeQuery
{
public string Format { get; set; }
public DateMath GreaterThan { get; set; }

public DateMath GreaterThanOrEqualTo { get; set; }
public DateMath LessThan { get; set; }
public DateMath LessThanOrEqualTo { get; set; }
public RangeRelation? Relation { get; set; }
public string TimeZone { get; set; }

/// <summary>
/// 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.
/// </summary>
[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.")]
public DateMath From { get; set; }
/// <summary>
/// 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.
/// </summary>
[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.")]
public DateMath To { get; set; }
/// <summary>
/// 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.
/// </summary>
[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.")]
public bool? IncludeLower { get; set; }
/// <summary>
/// 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.
/// </summary>
[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.")]
public bool? IncludeUpper { get; set; }

protected override bool Conditionless => IsConditionless(this);

internal override void InternalWrapInContainer(IQueryContainer c) => c.Range = this;
Expand All @@ -51,13 +101,16 @@ internal static bool IsConditionless(IDateRangeQuery q) => q.Field.IsConditionle
|| ((q.GreaterThanOrEqualTo == null || !q.GreaterThanOrEqualTo.IsValid)
&& (q.LessThanOrEqualTo == null || !q.LessThanOrEqualTo.IsValid)
&& (q.GreaterThan == null || !q.GreaterThan.IsValid)
&& (q.LessThan == null || !q.LessThan.IsValid));
&& (q.LessThan == null || !q.LessThan.IsValid)
#pragma warning disable CS0618 // Type or member is obsolete
&& (q.From == null || !q.From.IsValid)
&& (q.To == null || !q.To.IsValid));
#pragma warning restore CS0618 // Type or member is obsolete
}

[DataContract]
public class DateRangeQueryDescriptor<T>
: FieldNameQueryDescriptorBase<DateRangeQueryDescriptor<T>, IDateRangeQuery, T>
, IDateRangeQuery where T : class
: FieldNameQueryDescriptorBase<DateRangeQueryDescriptor<T>, IDateRangeQuery, T>, IDateRangeQuery where T : class
{
protected override bool Conditionless => DateRangeQuery.IsConditionless(this);
string IDateRangeQuery.Format { get; set; }
Expand All @@ -68,18 +121,18 @@ public class DateRangeQueryDescriptor<T>
RangeRelation? IDateRangeQuery.Relation { get; set; }
string IDateRangeQuery.TimeZone { get; set; }

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

public DateRangeQueryDescriptor<T> GreaterThan(DateMath from) => Assign(from, (a, v) => a.GreaterThan = v);
public DateRangeQueryDescriptor<T> GreaterThanOrEquals(DateMath from) => Assign(from, (a, v) => a.GreaterThanOrEqualTo = v);

public DateRangeQueryDescriptor<T> LessThan(DateMath to) => Assign(to, (a, v) => a.LessThan = v);

public DateRangeQueryDescriptor<T> LessThanOrEquals(DateMath to) => Assign(to, (a, v) => a.LessThanOrEqualTo = v);

public DateRangeQueryDescriptor<T> TimeZone(string timeZone) => Assign(timeZone, (a, v) => a.TimeZone = v);

public DateRangeQueryDescriptor<T> Format(string format) => Assign(format, (a, v) => a.Format = v);

public DateRangeQueryDescriptor<T> Relation(RangeRelation? relation) => Assign(relation, (a, v) => a.Relation = v);
}
}
68 changes: 60 additions & 8 deletions src/Nest/QueryDsl/TermLevel/Range/LongRangeQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System;
using System.Runtime.Serialization;
using Elasticsearch.Net.Utf8Json;

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

[DataMember(Name ="relation")]
[DataMember(Name = "relation")]
RangeRelation? Relation { get; set; }

/// <summary>
/// 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.
/// </summary>
[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.")]
[DataMember(Name = "from")]
long? From { get; set; }
/// <summary>
/// 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.
/// </summary>
[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.")]
[DataMember(Name = "to")]
long? To { get; set; }
/// <summary>
/// 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.
/// </summary>
[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.")]
[DataMember(Name = "include_lower")]
bool? IncludeLower { get; set; }
/// <summary>
/// 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.
/// </summary>
[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.")]
[DataMember(Name = "include_upper")]
bool? IncludeUpper { get; set; }
}

public class LongRangeQuery : FieldNameQueryBase, ILongRangeQuery
Expand All @@ -34,6 +60,27 @@ public class LongRangeQuery : FieldNameQueryBase, ILongRangeQuery
public long? LessThan { get; set; }
public long? LessThanOrEqualTo { get; set; }

/// <summary>
/// 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.
/// </summary>
[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.")]
public long? From { get; set; }
/// <summary>
/// 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.
/// </summary>
[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.")]
public long? To { get; set; }
/// <summary>
/// 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.
/// </summary>
[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.")]
public bool? IncludeLower { get; set; }
/// <summary>
/// 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.
/// </summary>
[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.")]
public bool? IncludeUpper { get; set; }

public RangeRelation? Relation { get; set; }
protected override bool Conditionless => IsConditionless(this);

Expand All @@ -43,13 +90,16 @@ internal static bool IsConditionless(ILongRangeQuery q) => q.Field.IsConditionle
|| q.GreaterThanOrEqualTo == null
&& q.LessThanOrEqualTo == null
&& q.GreaterThan == null
&& q.LessThan == null;
&& q.LessThan == null
#pragma warning disable CS0618 // Type or member is obsolete
&& q.From == null
&& q.To == null;
#pragma warning restore CS0618 // Type or member is obsolete
}

[DataContract]
public class LongRangeQueryDescriptor<T>
: FieldNameQueryDescriptorBase<LongRangeQueryDescriptor<T>, ILongRangeQuery, T>
, ILongRangeQuery where T : class
: FieldNameQueryDescriptorBase<LongRangeQueryDescriptor<T>, ILongRangeQuery, T>, ILongRangeQuery where T : class
{
protected override bool Conditionless => LongRangeQuery.IsConditionless(this);
long? ILongRangeQuery.GreaterThan { get; set; }
Expand All @@ -58,14 +108,16 @@ public class LongRangeQueryDescriptor<T>
long? ILongRangeQuery.LessThanOrEqualTo { get; set; }
RangeRelation? ILongRangeQuery.Relation { get; set; }

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

public LongRangeQueryDescriptor<T> Relation(RangeRelation? relation) => Assign(relation, (a, v) => a.Relation = v);
public LongRangeQueryDescriptor<T> GreaterThan(long? from) => Assign(from, (a, v) => a.GreaterThan = v);

public LongRangeQueryDescriptor<T> GreaterThanOrEquals(long? from) => Assign(from, (a, v) => a.GreaterThanOrEqualTo = v);

public LongRangeQueryDescriptor<T> LessThan(long? to) => Assign(to, (a, v) => a.LessThan = v);

public LongRangeQueryDescriptor<T> LessThanOrEquals(long? to) => Assign(to, (a, v) => a.LessThanOrEqualTo = v);
}
}
73 changes: 64 additions & 9 deletions src/Nest/QueryDsl/TermLevel/Range/NumericRangeQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System;
using System.Runtime.Serialization;
using Elasticsearch.Net.Utf8Json;

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

[DataMember(Name = "relation")]
RangeRelation? Relation { get; set; }

/// <summary>
/// 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.
/// </summary>
[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.")]
[DataMember(Name = "from")]
double? From { get; set; }

/// <summary>
/// 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.
/// </summary>
[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.")]
[DataMember(Name = "to")]
double? To { get; set; }

/// <summary>
/// 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.
/// </summary>
[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.")]
[DataMember(Name = "include_lower")]
bool? IncludeLower { get; set; }

/// <summary>
/// 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.
/// </summary>
[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.")]
[DataMember(Name = "include_upper")]
bool? IncludeUpper { get; set; }
}

public class NumericRangeQuery : FieldNameQueryBase, INumericRangeQuery
Expand All @@ -33,8 +62,29 @@ public class NumericRangeQuery : FieldNameQueryBase, INumericRangeQuery
public double? GreaterThanOrEqualTo { get; set; }
public double? LessThan { get; set; }
public double? LessThanOrEqualTo { get; set; }

public RangeRelation? Relation { get; set; }

/// <summary>
/// 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.
/// </summary>
[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.")]
public double? From { get; set; }
/// <summary>
/// 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.
/// </summary>
[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.")]
public double? To { get; set; }
/// <summary>
/// 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.
/// </summary>
[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.")]
public bool? IncludeLower { get; set; }
/// <summary>
/// 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.
/// </summary>
[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.")]
public bool? IncludeUpper { get; set; }

protected override bool Conditionless => IsConditionless(this);

internal override void InternalWrapInContainer(IQueryContainer c) => c.Range = this;
Expand All @@ -43,30 +93,35 @@ internal static bool IsConditionless(INumericRangeQuery q) => q.Field.IsConditio
|| q.GreaterThanOrEqualTo == null
&& q.LessThanOrEqualTo == null
&& q.GreaterThan == null
&& q.LessThan == null;
&& q.LessThan == null
#pragma warning disable CS0618 // Type or member is obsolete
&& q.From == null
&& q.To == null;
#pragma warning restore CS0618 // Type or member is obsolete
}

[DataContract]
public class NumericRangeQueryDescriptor<T>
: FieldNameQueryDescriptorBase<NumericRangeQueryDescriptor<T>, INumericRangeQuery, T>
, INumericRangeQuery where T : class
: FieldNameQueryDescriptorBase<NumericRangeQueryDescriptor<T>, INumericRangeQuery, T>, INumericRangeQuery where T : class
{
protected override bool Conditionless => NumericRangeQuery.IsConditionless(this);

double? INumericRangeQuery.GreaterThan { get; set; }
double? INumericRangeQuery.GreaterThanOrEqualTo { get; set; }
double? INumericRangeQuery.LessThan { get; set; }
double? INumericRangeQuery.LessThanOrEqualTo { get; set; }

RangeRelation? INumericRangeQuery.Relation { get; set; }

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

public NumericRangeQueryDescriptor<T> GreaterThan(double? from) => Assign(from, (a, v) => a.GreaterThan = v);
public NumericRangeQueryDescriptor<T> GreaterThanOrEquals(double? from) => Assign(from, (a, v) => a.GreaterThanOrEqualTo = v);

public NumericRangeQueryDescriptor<T> LessThan(double? to) => Assign(to, (a, v) => a.LessThan = v);

public NumericRangeQueryDescriptor<T> LessThanOrEquals(double? to) => Assign(to, (a, v) => a.LessThanOrEqualTo = v);

public NumericRangeQueryDescriptor<T> Relation(RangeRelation? relation) => Assign(relation, (a, v) => a.Relation = v);
}
}
Loading