File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed
Tests/Nest.Tests.Unit/Search/Sort Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,9 @@ public class SortDescriptor<T> where T : class
1919 [ JsonProperty ( "order" ) ]
2020 internal string _Order { get ; set ; }
2121
22+ [ JsonProperty ( "mode" ) ]
23+ internal string _Mode { get ; set ; }
24+
2225 [ JsonProperty ( "nested_filter" ) ]
2326 internal BaseFilter _NestedFilter { get ; set ; }
2427
@@ -70,6 +73,31 @@ public virtual SortDescriptor<T> Descending()
7073 this . _Order = "desc" ;
7174 return this ;
7275 }
76+
77+ public virtual SortDescriptor < T > NestedMin ( )
78+ {
79+ this . _Mode = "min" ;
80+ return this ;
81+ }
82+
83+ public virtual SortDescriptor < T > NestedMax ( )
84+ {
85+ this . _Mode = "max" ;
86+ return this ;
87+ }
88+
89+ public virtual SortDescriptor < T > NestedSum ( )
90+ {
91+ this . _Mode = "sum" ;
92+ return this ;
93+ }
94+
95+ public virtual SortDescriptor < T > NestedAvg ( )
96+ {
97+ this . _Mode = "avg" ;
98+ return this ;
99+ }
100+
73101 public virtual SortDescriptor < T > NestedFilter ( Func < FilterDescriptor < T > , BaseFilter > filterSelector )
74102 {
75103 filterSelector . ThrowIfNull ( "filterSelector" ) ;
Original file line number Diff line number Diff line change @@ -61,6 +61,32 @@ public void TestSortOnSortField()
6161 Assert . True ( json . JsonEquals ( expected ) , json ) ;
6262 }
6363
64+ [ Test ]
65+ public void TestSortOnNestedField ( )
66+ {
67+ var s = new SearchDescriptor < ElasticsearchProject > ( )
68+ . From ( 0 )
69+ . Size ( 10 )
70+ . Sort ( sort => sort
71+ . OnField ( e => e . Contributors . Suffix ( "age" ) ) // Sort projects by oldest contributor
72+ . NestedMax ( )
73+ . Descending ( )
74+ ) ;
75+ var json = TestElasticClient . Serialize ( s ) ;
76+ var expected = @"
77+ {
78+ from: 0,
79+ size: 10,
80+ sort: {
81+ ""contributors.age"": {
82+ ""order"": ""desc"",
83+ ""mode"": ""max""
84+ }
85+ }
86+ }" ;
87+ Assert . True ( json . JsonEquals ( expected ) , json ) ;
88+ }
89+
6490 [ Test ]
6591 public void TestSortAscending ( )
6692 {
You can’t perform that action at this time.
0 commit comments