Skip to content

Commit c98b2dc

Browse files
committed
Merge branch '5.x' of github.com:elastic/elasticsearch-net into 5.x
2 parents c953239 + de910b5 commit c98b2dc

File tree

2 files changed

+84
-10
lines changed

2 files changed

+84
-10
lines changed

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

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,103 @@
44

55
namespace Nest
66
{
7+
/// <summary>
8+
/// Allows to add one or more sort on specific fields.
9+
/// </summary>
710
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
811
[ContractJsonConverter(typeof(SortJsonConverter))]
912
public interface ISort
1013
{
14+
/// <summary>
15+
/// The field to sort on
16+
/// </summary>
1117
Field SortKey { get; }
1218

13-
[JsonProperty("missing")]
19+
/// <summary>
20+
/// Specifies how docs which are missing the field should be treated
21+
/// </summary>
22+
[JsonIgnore]
23+
[Obsolete("Use MissingValue")]
1424
string Missing { get; set; }
1525

26+
/// <summary>
27+
/// Specifies how docs which are missing the field should be treated
28+
/// </summary>
29+
[JsonProperty("missing")]
30+
object MissingValue { get; set; }
31+
32+
/// <summary>
33+
/// The sort order
34+
/// </summary>
1635
[JsonProperty("order")]
1736
SortOrder? Order { get; set; }
1837

38+
/// <summary>
39+
/// Elasticsearch supports sorting by array or multi-valued fields. <see cref="Mode"/>
40+
/// controls what array value is picked for sorting the document it belongs to.
41+
/// </summary>
1942
[JsonProperty("mode")]
2043
SortMode? Mode { get; set; }
2144

45+
/// <summary>
46+
/// A filter that the inner objects inside the nested path should match with in order for its field values
47+
/// to be taken into account by sorting.
48+
/// Common case is to repeat the query / filter inside the nested filter or query.
49+
/// </summary>
2250
[JsonProperty("nested_filter")]
2351
QueryContainer NestedFilter { get; set; }
2452

53+
/// <summary>
54+
/// Defines on which nested object to sort. The actual sort field must be a direct field inside
55+
/// this nested object. When sorting by nested field, this field is mandatory.
56+
/// </summary>
2557
[JsonProperty("nested_path")]
2658
Field NestedPath { get; set; }
2759
}
2860

61+
/// <inheritdoc/>
2962
public abstract class SortBase : ISort
3063
{
31-
public string Missing { get; set; }
64+
/// <inheritdoc/>
65+
[Obsolete("Use MissingValue")]
66+
public string Missing
67+
{
68+
get => MissingValue as string;
69+
set => MissingValue = value;
70+
}
71+
/// <inheritdoc/>
72+
public object MissingValue { get; set; }
73+
/// <inheritdoc/>
3274
public SortOrder? Order { get; set; }
75+
/// <inheritdoc/>
3376
public SortMode? Mode { get; set; }
77+
/// <inheritdoc/>
3478
public QueryContainer NestedFilter { get; set; }
79+
/// <inheritdoc/>
3580
public Field NestedPath { get; set; }
81+
/// <inheritdoc/>
3682
Field ISort.SortKey => this.SortKey;
83+
/// <summary>
84+
/// The field to sort on
85+
/// </summary>
3786
protected abstract Field SortKey { get; }
3887
}
3988

40-
public abstract class SortDescriptorBase<TDescriptor, TInterface, T> : DescriptorBase<TDescriptor, TInterface>, ISort
41-
where T : class
89+
public abstract class SortDescriptorBase<TDescriptor, TInterface, T> : DescriptorBase<TDescriptor, TInterface>, ISort
90+
where T : class
4291
where TDescriptor : SortDescriptorBase<TDescriptor, TInterface, T>, TInterface, ISort
4392
where TInterface : class, ISort
4493
{
4594
Field ISort.SortKey => this.SortKey;
4695

47-
string ISort.Missing { get; set; }
96+
[Obsolete("Use MissingValue")]
97+
string ISort.Missing
98+
{
99+
get => Self.MissingValue as string;
100+
set => Self.MissingValue = value;
101+
}
102+
103+
object ISort.MissingValue { get; set; }
48104

49105
SortOrder? ISort.Order { get; set; }
50106

@@ -71,11 +127,12 @@ public virtual TDescriptor NestedFilter(Func<QueryContainerDescriptor<T>, QueryC
71127

72128
public virtual TDescriptor NestedPath(Expression<Func<T, object>> objectPath) => Assign(a => a.NestedPath = objectPath);
73129

74-
public virtual TDescriptor MissingLast() => Assign(a => a.Missing = "_last");
130+
public virtual TDescriptor MissingLast() => Assign(a => a.MissingValue = "_last");
75131

76-
public virtual TDescriptor MissingFirst() => Assign(a => a.Missing = "_first");
132+
public virtual TDescriptor MissingFirst() => Assign(a => a.MissingValue = "_first");
77133

78-
public virtual TDescriptor MissingValue(string value) => Assign(a => a.Missing = value);
134+
public virtual TDescriptor MissingValue(string value) => Assign(a => a.MissingValue = value);
79135

136+
public virtual TDescriptor Missing(object value) => Assign(a => a.MissingValue = value);
80137
}
81-
}
138+
}

src/Tests/Search/Request/SortUsageTests.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ public SortUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(clust
3737
unmapped_type = "date"
3838
}
3939
},
40+
new {
41+
numberOfCommits = new {
42+
missing = -1,
43+
order = "desc"
44+
}
45+
},
4046
new {
4147
_geo_distance = new {
4248
location = new [] {
@@ -86,6 +92,11 @@ public SortUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(clust
8692
.NestedPath(p => p.Tags)
8793
.NestedFilter(q => q.MatchAll())
8894
)
95+
.Field(f => f
96+
.Field(p => p.NumberOfCommits)
97+
.Order(SortOrder.Descending)
98+
.Missing(-1)
99+
)
89100
.GeoDistance(g => g
90101
.Field(p => p.Location)
91102
.DistanceType(GeoDistanceType.Arc)
@@ -118,12 +129,18 @@ public SortUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(clust
118129
{
119130
Field = Field<Project>(p=>p.LastActivity),
120131
Order = SortOrder.Descending,
121-
Missing = "_last",
132+
MissingValue = "_last",
122133
UnmappedType = FieldType.Date,
123134
Mode = SortMode.Average,
124135
NestedPath = Field<Project>(p=>p.Tags),
125136
NestedFilter = new MatchAllQuery(),
126137
},
138+
new SortField
139+
{
140+
Field = Field<Project>(p=>p.NumberOfCommits),
141+
Order = SortOrder.Descending,
142+
MissingValue = -1
143+
},
127144
new GeoDistanceSort
128145
{
129146
Field = "location",

0 commit comments

Comments
 (0)