Skip to content

Commit ad2a25d

Browse files
authored
Consistent Sort type names (#3646)
* Consistent Sort type naming This commit updates sort type names for consistency - Rename SortGeoDistance to GeoDistanceSort - Rename SortField to FieldSort - Rename SortScript to ScriptSort -Rename property GeoUnit to Unit on GeoDistanceSort Fixes #3454 * Remove NestedPath and NestedFilter This commit removes NestedPath and NestedFilter. Both were deprecated in 6.1.0 in favour of Nested.
1 parent cd854ff commit ad2a25d

File tree

13 files changed

+69
-103
lines changed

13 files changed

+69
-103
lines changed

src/Nest/CommonOptions/Sorting/SortFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public ISort Deserialize(ref JsonReader reader, IJsonFormatterResolver formatter
6262
else
6363
{
6464
var field = sortProperty.Utf8String();
65-
var sortField = formatterResolver.GetFormatter<SortField>()
65+
var sortField = formatterResolver.GetFormatter<FieldSort>()
6666
.Deserialize(ref reader, formatterResolver);
6767
sortField.Field = field;
6868
sort = sortField;

src/Nest/Document/Multiple/ScrollAll/ScrollAllObservable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public ScrollAllObservable(
3030
_scrollAllRequest = scrollAllRequest;
3131
_searchRequest = scrollAllRequest?.Search ?? new SearchRequest<T>();
3232
if (_searchRequest.Sort == null)
33-
_searchRequest.Sort = SortField.ByDocumentOrder;
33+
_searchRequest.Sort = FieldSort.ByDocumentOrder;
3434
_searchRequest.RequestParameters.Scroll = _scrollAllRequest.ScrollTime.ToTimeSpan();
3535
_client = client;
3636
_compositeCancelTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);

src/Nest/Search/Search/Sort/SortField.cs renamed to src/Nest/Search/Search/Sort/FieldSort.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,37 @@ public interface IFieldSort : ISort
1717
FieldType? UnmappedType { get; set; }
1818
}
1919

20-
public class SortField : SortBase, IFieldSort
20+
public class FieldSort : SortBase, IFieldSort
2121
{
22-
public static readonly IList<ISort> ByDocumentOrder = new ReadOnlyCollection<ISort>(new List<ISort> { new SortField { Field = "_doc" } });
22+
public static readonly IList<ISort> ByDocumentOrder = new ReadOnlyCollection<ISort>(new List<ISort> { new FieldSort { Field = "_doc" } });
2323
public Field Field { get; set; }
2424
public bool? IgnoreUnmappedFields { get; set; }
2525
public FieldType? UnmappedType { get; set; }
2626
protected override Field SortKey => Field;
2727
}
2828

29-
public class SortFieldDescriptor<T> : SortDescriptorBase<SortFieldDescriptor<T>, IFieldSort, T>, IFieldSort where T : class
29+
public class FieldSortDescriptor<T> : SortDescriptorBase<FieldSortDescriptor<T>, IFieldSort, T>, IFieldSort where T : class
3030
{
3131
private Field _field;
3232
protected override Field SortKey => _field;
3333

3434
bool? IFieldSort.IgnoreUnmappedFields { get; set; }
3535
FieldType? IFieldSort.UnmappedType { get; set; }
3636

37-
public virtual SortFieldDescriptor<T> Field(Field field)
37+
public virtual FieldSortDescriptor<T> Field(Field field)
3838
{
3939
_field = field;
4040
return this;
4141
}
4242

43-
public virtual SortFieldDescriptor<T> Field(Expression<Func<T, object>> objectPath)
43+
public virtual FieldSortDescriptor<T> Field(Expression<Func<T, object>> objectPath)
4444
{
4545
_field = objectPath;
4646
return this;
4747
}
4848

49-
public virtual SortFieldDescriptor<T> UnmappedType(FieldType? type) => Assign(type, (a, v) => a.UnmappedType = v);
49+
public virtual FieldSortDescriptor<T> UnmappedType(FieldType? type) => Assign(type, (a, v) => a.UnmappedType = v);
5050

51-
public virtual SortFieldDescriptor<T> IgnoreUnmappedFields(bool? ignore = true) => Assign(ignore, (a, v) => a.IgnoreUnmappedFields = v);
51+
public virtual FieldSortDescriptor<T> IgnoreUnmappedFields(bool? ignore = true) => Assign(ignore, (a, v) => a.IgnoreUnmappedFields = v);
5252
}
5353
}

src/Nest/Search/Search/Sort/SortGeoDistance.cs renamed to src/Nest/Search/Search/Sort/GeoDistanceSort.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public interface IGeoDistanceSort : ISort
2121

2222
/// <summary> The unit to use when computing sort values. The default is m (meters) </summary>
2323
[DataMember(Name ="unit")]
24-
DistanceUnit? GeoUnit { get; set; }
24+
DistanceUnit? Unit { get; set; }
2525

2626
/// <summary>
2727
/// Indicates if the unmapped field should be treated as a missing value. Setting it to `true` is equivalent to specifying
@@ -41,8 +41,8 @@ public class GeoDistanceSort : SortBase, IGeoDistanceSort
4141

4242
public Field Field { get; set; }
4343

44-
/// <inheritdoc cref="IGeoDistanceSort.GeoUnit" />
45-
public DistanceUnit? GeoUnit { get; set; }
44+
/// <inheritdoc cref="IGeoDistanceSort.Unit" />
45+
public DistanceUnit? Unit { get; set; }
4646

4747
/// <inheritdoc cref="IGeoDistanceSort.IgnoreUnmapped" />
4848
public bool? IgnoreUnmapped { get; set; }
@@ -52,32 +52,32 @@ public class GeoDistanceSort : SortBase, IGeoDistanceSort
5252
}
5353

5454
/// <inheritdoc cref="IGeoDistanceSort" />
55-
public class SortGeoDistanceDescriptor<T> : SortDescriptorBase<SortGeoDistanceDescriptor<T>, IGeoDistanceSort, T>, IGeoDistanceSort
55+
public class GeoDistanceSortDescriptor<T> : SortDescriptorBase<GeoDistanceSortDescriptor<T>, IGeoDistanceSort, T>, IGeoDistanceSort
5656
where T : class
5757
{
5858
protected override Field SortKey => "_geo_distance";
5959
GeoDistanceType? IGeoDistanceSort.DistanceType { get; set; }
6060

6161
Field IGeoDistanceSort.Field { get; set; }
62-
DistanceUnit? IGeoDistanceSort.GeoUnit { get; set; }
62+
DistanceUnit? IGeoDistanceSort.Unit { get; set; }
6363
bool? IGeoDistanceSort.IgnoreUnmapped { get; set; }
6464
IEnumerable<GeoLocation> IGeoDistanceSort.Points { get; set; }
6565

66-
public SortGeoDistanceDescriptor<T> Points(params GeoLocation[] geoLocations) => Assign(geoLocations, (a, v) => a.Points = v);
66+
public GeoDistanceSortDescriptor<T> Points(params GeoLocation[] geoLocations) => Assign(geoLocations, (a, v) => a.Points = v);
6767

68-
public SortGeoDistanceDescriptor<T> Points(IEnumerable<GeoLocation> geoLocations) => Assign(geoLocations, (a, v) => a.Points = v);
68+
public GeoDistanceSortDescriptor<T> Points(IEnumerable<GeoLocation> geoLocations) => Assign(geoLocations, (a, v) => a.Points = v);
6969

70-
/// <inheritdoc cref="IGeoDistanceSort.GeoUnit" />
71-
public SortGeoDistanceDescriptor<T> Unit(DistanceUnit? unit) => Assign(unit, (a, v) => a.GeoUnit = v);
70+
/// <inheritdoc cref="IGeoDistanceSort.Unit" />
71+
public GeoDistanceSortDescriptor<T> Unit(DistanceUnit? unit) => Assign(unit, (a, v) => a.Unit = v);
7272

7373
/// <inheritdoc cref="IGeoDistanceSort.DistanceType" />
74-
public SortGeoDistanceDescriptor<T> DistanceType(GeoDistanceType? distanceType) => Assign(distanceType, (a, v) => a.DistanceType = v);
74+
public GeoDistanceSortDescriptor<T> DistanceType(GeoDistanceType? distanceType) => Assign(distanceType, (a, v) => a.DistanceType = v);
7575

76-
public SortGeoDistanceDescriptor<T> Field(Field field) => Assign(field, (a, v) => a.Field = v);
76+
public GeoDistanceSortDescriptor<T> Field(Field field) => Assign(field, (a, v) => a.Field = v);
7777

78-
public SortGeoDistanceDescriptor<T> Field(Expression<Func<T, object>> objectPath) => Assign(objectPath, (a, v) => a.Field = v);
78+
public GeoDistanceSortDescriptor<T> Field(Expression<Func<T, object>> objectPath) => Assign(objectPath, (a, v) => a.Field = v);
7979

8080
/// <inheritdoc cref="IGeoDistanceSort.IgnoreUnmapped" />
81-
public SortGeoDistanceDescriptor<T> IgnoreUnmapped(bool? ignoreUnmapped = true) => Assign(ignoreUnmapped, (a, v) => a.IgnoreUnmapped = v);
81+
public GeoDistanceSortDescriptor<T> IgnoreUnmapped(bool? ignoreUnmapped = true) => Assign(ignoreUnmapped, (a, v) => a.IgnoreUnmapped = v);
8282
}
8383
}

src/Nest/Search/Search/Sort/SortScript.cs renamed to src/Nest/Search/Search/Sort/ScriptSort.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class ScriptSort : SortBase, IScriptSort
2424
protected override Field SortKey => "_script";
2525
}
2626

27-
public class SortScriptDescriptor<T> : SortDescriptorBase<SortScriptDescriptor<T>, IScriptSort, T>, IScriptSort
27+
public class ScriptSortDescriptor<T> : SortDescriptorBase<ScriptSortDescriptor<T>, IScriptSort, T>, IScriptSort
2828
where T : class
2929
{
3030
protected override Field SortKey => "_script";
@@ -33,9 +33,9 @@ public class SortScriptDescriptor<T> : SortDescriptorBase<SortScriptDescriptor<T
3333

3434
string IScriptSort.Type { get; set; }
3535

36-
public virtual SortScriptDescriptor<T> Type(string type) => Assign(type, (a, v) => a.Type = v);
36+
public virtual ScriptSortDescriptor<T> Type(string type) => Assign(type, (a, v) => a.Type = v);
3737

38-
public SortScriptDescriptor<T> Script(Func<ScriptDescriptor, IScript> scriptSelector) =>
38+
public ScriptSortDescriptor<T> Script(Func<ScriptDescriptor, IScript> scriptSelector) =>
3939
Assign(scriptSelector, (a, v) => a.Script = v?.Invoke(new ScriptDescriptor()));
4040
}
4141
}

src/Nest/Search/Search/Sort/SortBase.cs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,9 @@ public interface ISort
2626
/// <summary>
2727
/// Specifies the path and filter to apply when sorting on a nested field
2828
/// </summary>
29-
/// <remarks>
30-
/// Valid in Elasticsearch 6.1.0+
31-
/// </remarks>
3229
[DataMember(Name ="nested")]
3330
INestedSort Nested { get; set; }
3431

35-
/// <summary>
36-
/// Specifies the filter to apply when sorting on a nested field
37-
/// </summary>
38-
[DataMember(Name ="nested_filter")]
39-
[Obsolete("Deprecated in 6.1.0. Use Nested. Will be removed in 7.x")]
40-
QueryContainer NestedFilter { get; set; }
41-
42-
/// <summary>
43-
/// Specifies the path to apply when sorting on a nested field
44-
/// </summary>
45-
[DataMember(Name ="nested_path")]
46-
[Obsolete("Deprecated in 6.1.0. Use Nested. Will be removed in 7.x")]
47-
Field NestedPath { get; set; }
48-
4932
/// <summary>
5033
/// Controls the order of sorting
5134
/// </summary>
@@ -70,14 +53,6 @@ public abstract class SortBase : ISort
7053
/// <inheritdoc />
7154
public INestedSort Nested { get; set; }
7255

73-
/// <inheritdoc />
74-
[Obsolete("Deprecated in 6.1.0. Use Nested. Will be removed in 7.x")]
75-
public QueryContainer NestedFilter { get; set; }
76-
77-
/// <inheritdoc />
78-
[Obsolete("Deprecated in 6.1.0. Use Nested. Will be removed in 7.x")]
79-
public Field NestedPath { get; set; }
80-
8156
/// <inheritdoc />
8257
public SortOrder? Order { get; set; }
8358

@@ -103,8 +78,6 @@ public abstract class SortDescriptorBase<TDescriptor, TInterface, T> : Descripto
10378
object ISort.Missing { get; set; }
10479
SortMode? ISort.Mode { get; set; }
10580
INestedSort ISort.Nested { get; set; }
106-
QueryContainer ISort.NestedFilter { get; set; }
107-
Field ISort.NestedPath { get; set; }
10881
SortOrder? ISort.Order { get; set; }
10982
Field ISort.SortKey => SortKey;
11083

@@ -124,19 +97,6 @@ public abstract class SortDescriptorBase<TDescriptor, TInterface, T> : Descripto
12497
/// <inheritdoc cref="ISort.Mode" />
12598
public virtual TDescriptor Mode(SortMode? mode) => Assign(mode, (a, v) => a.Mode = v);
12699

127-
/// <inheritdoc cref="ISort.NestedFilter" />
128-
[Obsolete("Deprecated in 6.1.0. Use Nested. Will be removed in 7.x")]
129-
public virtual TDescriptor NestedFilter(Func<QueryContainerDescriptor<T>, QueryContainer> filterSelector) =>
130-
Assign(filterSelector, (a, v) => a.NestedFilter = v?.Invoke(new QueryContainerDescriptor<T>()));
131-
132-
/// <inheritdoc cref="ISort.NestedPath" />
133-
[Obsolete("Deprecated in 6.1.0. Use Nested. Will be removed in 7.x")]
134-
public virtual TDescriptor NestedPath(Field path) => Assign(path, (a, v) => a.NestedPath = v);
135-
136-
/// <inheritdoc cref="ISort.NestedPath" />
137-
[Obsolete("Deprecated in 6.1.0. Use Nested. Will be removed in 7.x")]
138-
public virtual TDescriptor NestedPath(Expression<Func<T, object>> objectPath) => Assign(objectPath, (a, v) => a.NestedPath = v);
139-
140100
/// <summary>
141101
/// Specifies that documents which are missing the sort field should be ordered last
142102
/// </summary>

src/Nest/Search/Search/Sort/SortDescriptor.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@ public class SortDescriptor<T> : DescriptorPromiseBase<SortDescriptor<T>, IList<
1111
public SortDescriptor() : base(new List<ISort>()) { }
1212

1313
public SortDescriptor<T> Ascending(Expression<Func<T, object>> objectPath) =>
14-
Assign(objectPath, (a, v) => a.Add(new SortField { Field = v, Order = SortOrder.Ascending }));
14+
Assign(objectPath, (a, v) => a.Add(new FieldSort { Field = v, Order = SortOrder.Ascending }));
1515

1616
public SortDescriptor<T> Descending(Expression<Func<T, object>> objectPath) =>
17-
Assign(objectPath, (a, v) => a.Add(new SortField { Field = v, Order = SortOrder.Descending }));
17+
Assign(objectPath, (a, v) => a.Add(new FieldSort { Field = v, Order = SortOrder.Descending }));
1818

19-
public SortDescriptor<T> Ascending(Field field) => Assign(field, (a, v) => a.Add(new SortField { Field = v, Order = SortOrder.Ascending }));
19+
public SortDescriptor<T> Ascending(Field field) => Assign(field, (a, v) => a.Add(new FieldSort { Field = v, Order = SortOrder.Ascending }));
2020

21-
public SortDescriptor<T> Descending(Field field) => Assign(field, (a, v) => a.Add(new SortField { Field = v, Order = SortOrder.Descending }));
21+
public SortDescriptor<T> Descending(Field field) => Assign(field, (a, v) => a.Add(new FieldSort { Field = v, Order = SortOrder.Descending }));
2222

2323
public SortDescriptor<T> Ascending(SortSpecialField field) =>
24-
Assign(field.GetStringValue(), (a, v) => a.Add(new SortField { Field = v, Order = SortOrder.Ascending }));
24+
Assign(field.GetStringValue(), (a, v) => a.Add(new FieldSort { Field = v, Order = SortOrder.Ascending }));
2525

2626
public SortDescriptor<T> Descending(SortSpecialField field) =>
27-
Assign(field.GetStringValue(), (a, v) => a.Add(new SortField { Field = v, Order = SortOrder.Descending }));
27+
Assign(field.GetStringValue(), (a, v) => a.Add(new FieldSort { Field = v, Order = SortOrder.Descending }));
2828

29-
public SortDescriptor<T> Field(Func<SortFieldDescriptor<T>, IFieldSort> sortSelector) =>
30-
AddSort(sortSelector?.Invoke(new SortFieldDescriptor<T>()));
29+
public SortDescriptor<T> Field(Func<FieldSortDescriptor<T>, IFieldSort> sortSelector) =>
30+
AddSort(sortSelector?.Invoke(new FieldSortDescriptor<T>()));
3131

32-
public SortDescriptor<T> Field(Field field, SortOrder order) => AddSort(new SortField { Field = field, Order = order });
32+
public SortDescriptor<T> Field(Field field, SortOrder order) => AddSort(new FieldSort { Field = field, Order = order });
3333

3434
public SortDescriptor<T> Field(Expression<Func<T, object>> field, SortOrder order) =>
35-
AddSort(new SortField { Field = field, Order = order });
35+
AddSort(new FieldSort { Field = field, Order = order });
3636

37-
public SortDescriptor<T> GeoDistance(Func<SortGeoDistanceDescriptor<T>, IGeoDistanceSort> sortSelector) =>
38-
AddSort(sortSelector?.Invoke(new SortGeoDistanceDescriptor<T>()));
37+
public SortDescriptor<T> GeoDistance(Func<GeoDistanceSortDescriptor<T>, IGeoDistanceSort> sortSelector) =>
38+
AddSort(sortSelector?.Invoke(new GeoDistanceSortDescriptor<T>()));
3939

40-
public SortDescriptor<T> Script(Func<SortScriptDescriptor<T>, IScriptSort> sortSelector) =>
41-
AddSort(sortSelector?.Invoke(new SortScriptDescriptor<T>()));
40+
public SortDescriptor<T> Script(Func<ScriptSortDescriptor<T>, IScriptSort> sortSelector) =>
41+
AddSort(sortSelector?.Invoke(new ScriptSortDescriptor<T>()));
4242

4343
private SortDescriptor<T> AddSort(ISort sort) => sort == null ? this : Assign(sort, (a, v) => a.Add(v));
4444
}

src/Tests/Tests/Aggregations/Metric/TopHits/TopHitsAggregationUsageTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public TopHitsAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) : ba
144144
{
145145
Sort = new List<ISort>
146146
{
147-
new SortField { Field = Field<Project>(p => p.StartedOn), Order = SortOrder.Descending },
147+
new FieldSort { Field = Field<Project>(p => p.StartedOn), Order = SortOrder.Descending },
148148
new ScriptSort
149149
{
150150
Type = "number",

src/Tests/Tests/Aggregations/Pipeline/BucketSort/BucketSortAggregationUsageTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public BucketSortAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage us
8080
{
8181
Sort = new List<ISort>
8282
{
83-
new SortField { Field = "commits", Order = SortOrder.Descending }
83+
new FieldSort { Field = "commits", Order = SortOrder.Descending }
8484
},
8585
From = 0,
8686
Size = 3,

src/Tests/Tests/Document/Multiple/ReindexOnServer/ReindexOnServerApiTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public ReindexOnServerApiTests(IntrusiveOperationCluster cluster, EndpointUsage
7878
{
7979
Index = CallIsolatedValue,
8080
Query = new MatchQuery { Field = Field<Test>(p => p.Flag), Query = "bar" },
81-
Sort = new List<ISort> { new SortField { Field = "id", Order = SortOrder.Ascending } },
81+
Sort = new List<ISort> { new FieldSort { Field = "id", Order = SortOrder.Ascending } },
8282
Size = 100
8383
},
8484
Destination = new ReindexDestination

0 commit comments

Comments
 (0)