3
3
using System ;
4
4
using System . Collections . Generic ;
5
5
using System . Linq ;
6
+ using System . Linq . Expressions ;
6
7
using System . Text ;
7
8
8
9
namespace Nest
@@ -23,6 +24,22 @@ public interface ITopHitsAggregator : IMetricAggregator
23
24
24
25
[ JsonProperty ( "_source" ) ]
25
26
ISourceFilter Source { get ; set ; }
27
+
28
+ [ JsonProperty ( "highlight" ) ]
29
+ IHighlightRequest Highlight { get ; set ; }
30
+
31
+ [ JsonProperty ( "explain" ) ]
32
+ bool ? Explain { get ; set ; }
33
+
34
+ [ JsonProperty ( "script_fields" ) ]
35
+ [ JsonConverter ( typeof ( DictionaryKeysAreNotPropertyNamesJsonConverter ) ) ]
36
+ IDictionary < string , IScriptFilter > ScriptFields { get ; set ; }
37
+
38
+ [ JsonProperty ( "fielddata_fields" ) ]
39
+ IEnumerable < PropertyPathMarker > FieldDataFields { get ; set ; }
40
+
41
+ [ JsonProperty ( "version" ) ]
42
+ bool ? Version { get ; set ; }
26
43
}
27
44
28
45
public class TopHitsAggregator : MetricAggregator , ITopHitsAggregator
@@ -31,6 +48,11 @@ public class TopHitsAggregator : MetricAggregator, ITopHitsAggregator
31
48
public int ? Size { get ; set ; }
32
49
public IList < KeyValuePair < PropertyPathMarker , ISort > > Sort { get ; set ; }
33
50
public ISourceFilter Source { get ; set ; }
51
+ public IHighlightRequest Highlight { get ; set ; }
52
+ public bool ? Explain { get ; set ; }
53
+ public IDictionary < string , IScriptFilter > ScriptFields { get ; set ; }
54
+ public IEnumerable < PropertyPathMarker > FieldDataFields { get ; set ; }
55
+ public bool ? Version { get ; set ; }
34
56
}
35
57
36
58
public class TopHitsAggregationDescriptor < T >
@@ -47,6 +69,16 @@ public class TopHitsAggregationDescriptor<T>
47
69
48
70
ISourceFilter ITopHitsAggregator . Source { get ; set ; }
49
71
72
+ IHighlightRequest ITopHitsAggregator . Highlight { get ; set ; }
73
+
74
+ bool ? ITopHitsAggregator . Explain { get ; set ; }
75
+
76
+ IDictionary < string , IScriptFilter > ITopHitsAggregator . ScriptFields { get ; set ; }
77
+
78
+ IEnumerable < PropertyPathMarker > ITopHitsAggregator . FieldDataFields { get ; set ; }
79
+
80
+ bool ? ITopHitsAggregator . Version { get ; set ; }
81
+
50
82
public TopHitsAggregationDescriptor < T > From ( int from )
51
83
{
52
84
this . Self . From = from ;
@@ -87,5 +119,57 @@ public TopHitsAggregationDescriptor<T> Source(Func<SearchSourceDescriptor<T>, Se
87
119
this . Self . Source = sourceSelector ( new SearchSourceDescriptor < T > ( ) ) ;
88
120
return this ;
89
121
}
122
+
123
+ public TopHitsAggregationDescriptor < T > Highlight ( Func < HighlightDescriptor < T > , HighlightDescriptor < T > > highlightDescriptor )
124
+ {
125
+ highlightDescriptor . ThrowIfNull ( "highlightDescriptor" ) ;
126
+ this . Self . Highlight = highlightDescriptor ( new HighlightDescriptor < T > ( ) ) ;
127
+ return this ;
128
+ }
129
+
130
+ public TopHitsAggregationDescriptor < T > Explain ( bool explain = true )
131
+ {
132
+ this . Self . Explain = explain ;
133
+ return this ;
134
+ }
135
+
136
+ public TopHitsAggregationDescriptor < T > ScriptFields (
137
+ Func < FluentDictionary < string , Func < ScriptFilterDescriptor , ScriptFilterDescriptor > > ,
138
+ FluentDictionary < string , Func < ScriptFilterDescriptor , ScriptFilterDescriptor > > > scriptFields )
139
+ {
140
+ scriptFields . ThrowIfNull ( "scriptFields" ) ;
141
+ var scriptFieldDescriptors = scriptFields ( new FluentDictionary < string , Func < ScriptFilterDescriptor , ScriptFilterDescriptor > > ( ) ) ;
142
+ if ( scriptFieldDescriptors == null || scriptFieldDescriptors . All ( d => d . Value == null ) )
143
+ {
144
+ Self . ScriptFields = null ;
145
+ return this ;
146
+ }
147
+ Self . ScriptFields = new FluentDictionary < string , IScriptFilter > ( ) ;
148
+ foreach ( var d in scriptFieldDescriptors )
149
+ {
150
+ if ( d . Value == null )
151
+ continue ;
152
+ Self . ScriptFields . Add ( d . Key , d . Value ( new ScriptFilterDescriptor ( ) ) ) ;
153
+ }
154
+ return this ;
155
+ }
156
+
157
+ public TopHitsAggregationDescriptor < T > FieldDataFields ( params PropertyPathMarker [ ] fields )
158
+ {
159
+ this . Self . FieldDataFields = fields ;
160
+ return this ;
161
+ }
162
+
163
+ public TopHitsAggregationDescriptor < T > FieldDataFields ( params Expression < Func < T , object > > [ ] objectPaths )
164
+ {
165
+ this . Self . FieldDataFields = objectPaths . Select ( e => ( PropertyPathMarker ) e ) ;
166
+ return this ;
167
+ }
168
+
169
+ public TopHitsAggregationDescriptor < T > Version ( bool version = true )
170
+ {
171
+ this . Self . Version = version ;
172
+ return this ;
173
+ }
90
174
}
91
175
}
0 commit comments