24
24
import org .elasticsearch .common .io .stream .NamedWriteable ;
25
25
import org .elasticsearch .common .io .stream .StreamInput ;
26
26
import org .elasticsearch .common .io .stream .Writeable ;
27
- import org .elasticsearch .common .io .stream .Writeable .Reader ;
28
27
import org .elasticsearch .common .lucene .search .function .ScoreFunction ;
29
28
import org .elasticsearch .common .xcontent .XContent ;
30
29
import org .elasticsearch .index .query .QueryBuilder ;
31
30
import org .elasticsearch .index .query .QueryParser ;
32
31
import org .elasticsearch .index .query .functionscore .ScoreFunctionBuilder ;
33
32
import org .elasticsearch .index .query .functionscore .ScoreFunctionParser ;
33
+ import org .elasticsearch .search .aggregations .Aggregation ;
34
+ import org .elasticsearch .search .aggregations .AggregationBuilder ;
35
+ import org .elasticsearch .search .aggregations .Aggregator ;
36
+ import org .elasticsearch .search .aggregations .InternalAggregation ;
37
+ import org .elasticsearch .search .aggregations .PipelineAggregationBuilder ;
34
38
import org .elasticsearch .search .aggregations .bucket .significant .SignificantTerms ;
35
39
import org .elasticsearch .search .aggregations .bucket .significant .heuristics .SignificanceHeuristic ;
36
40
import org .elasticsearch .search .aggregations .bucket .significant .heuristics .SignificanceHeuristicParser ;
41
+ import org .elasticsearch .search .aggregations .pipeline .PipelineAggregator ;
37
42
import org .elasticsearch .search .aggregations .pipeline .movavg .MovAvgPipelineAggregator ;
38
43
import org .elasticsearch .search .aggregations .pipeline .movavg .models .MovAvgModel ;
39
44
import org .elasticsearch .search .fetch .FetchSubPhase ;
42
47
43
48
import java .util .List ;
44
49
import java .util .Map ;
50
+ import java .util .TreeMap ;
45
51
46
52
import static java .util .Collections .emptyList ;
47
53
import static java .util .Collections .emptyMap ;
@@ -94,16 +100,28 @@ default Map<String, Suggester<?>> getSuggesters() {
94
100
default List <QuerySpec <?>> getQueries () {
95
101
return emptyList ();
96
102
}
103
+ /**
104
+ * The new {@link Aggregation}s added by this plugin.
105
+ */
106
+ default List <AggregationSpec > getAggregations () {
107
+ return emptyList ();
108
+ }
109
+ /**
110
+ * The new {@link PipelineAggregator}s added by this plugin.
111
+ */
112
+ default List <PipelineAggregationSpec > getPipelineAggregations () {
113
+ return emptyList ();
114
+ }
97
115
98
116
/**
99
117
* Specification of custom {@link ScoreFunction}.
100
118
*/
101
119
class ScoreFunctionSpec <T extends ScoreFunctionBuilder <T >> extends SearchExtensionSpec <T , ScoreFunctionParser <T >> {
102
- public ScoreFunctionSpec (ParseField name , Reader <T > reader , ScoreFunctionParser <T > parser ) {
120
+ public ScoreFunctionSpec (ParseField name , Writeable . Reader <T > reader , ScoreFunctionParser <T > parser ) {
103
121
super (name , reader , parser );
104
122
}
105
123
106
- public ScoreFunctionSpec (String name , Reader <T > reader , ScoreFunctionParser <T > parser ) {
124
+ public ScoreFunctionSpec (String name , Writeable . Reader <T > reader , ScoreFunctionParser <T > parser ) {
107
125
super (name , reader , parser );
108
126
}
109
127
}
@@ -122,7 +140,7 @@ class QuerySpec<T extends QueryBuilder> extends SearchExtensionSpec<T, QueryPars
122
140
* {@link StreamInput}
123
141
* @param parser the parser the reads the query builder from xcontent
124
142
*/
125
- public QuerySpec (ParseField name , Reader <T > reader , QueryParser <T > parser ) {
143
+ public QuerySpec (ParseField name , Writeable . Reader <T > reader , QueryParser <T > parser ) {
126
144
super (name , reader , parser );
127
145
}
128
146
@@ -135,10 +153,143 @@ public QuerySpec(ParseField name, Reader<T> reader, QueryParser<T> parser) {
135
153
* {@link StreamInput}
136
154
* @param parser the parser the reads the query builder from xcontent
137
155
*/
138
- public QuerySpec (String name , Reader <T > reader , QueryParser <T > parser ) {
156
+ public QuerySpec (String name , Writeable . Reader <T > reader , QueryParser <T > parser ) {
139
157
super (name , reader , parser );
140
158
}
141
159
}
160
+ /**
161
+ * Specification for an {@link Aggregation}.
162
+ */
163
+ public static class AggregationSpec extends SearchExtensionSpec <AggregationBuilder , Aggregator .Parser > {
164
+ private final Map <String , Writeable .Reader <? extends InternalAggregation >> resultReaders = new TreeMap <>();
165
+
166
+ /**
167
+ * Specification for an {@link Aggregation}.
168
+ *
169
+ * @param name holds the names by which this aggregation might be parsed. The {@link ParseField#getPreferredName()} is special as it
170
+ * is the name by under which the reader is registered. So it is the name that the {@link AggregationBuilder} should return
171
+ * from {@link NamedWriteable#getWriteableName()}.
172
+ * @param reader the reader registered for this aggregation's builder. Typically a reference to a constructor that takes a
173
+ * {@link StreamInput}
174
+ * @param parser the parser the reads the aggregation builder from xcontent
175
+ */
176
+ public AggregationSpec (ParseField name , Writeable .Reader <? extends AggregationBuilder > reader , Aggregator .Parser parser ) {
177
+ super (name , reader , parser );
178
+ }
179
+
180
+ /**
181
+ * Specification for an {@link Aggregation}.
182
+ *
183
+ * @param name the name by which this aggregation might be parsed or deserialized. Make sure that the {@link AggregationBuilder}
184
+ * returns this from {@link NamedWriteable#getWriteableName()}.
185
+ * @param reader the reader registered for this aggregation's builder. Typically a reference to a constructor that takes a
186
+ * {@link StreamInput}
187
+ * @param parser the parser the reads the aggregation builder from xcontent
188
+ */
189
+ public AggregationSpec (String name , Writeable .Reader <? extends AggregationBuilder > reader , Aggregator .Parser parser ) {
190
+ super (name , reader , parser );
191
+ }
192
+
193
+ /**
194
+ * Add a reader for the shard level results of the aggregation with {@linkplain #getName}'s {@link ParseField#getPreferredName()} as
195
+ * the {@link NamedWriteable#getWriteableName()}.
196
+ */
197
+ public AggregationSpec addResultReader (Writeable .Reader <? extends InternalAggregation > resultReader ) {
198
+ return addResultReader (getName ().getPreferredName (), resultReader );
199
+ }
200
+
201
+ /**
202
+ * Add a reader for the shard level results of the aggregation.
203
+ */
204
+ public AggregationSpec addResultReader (String writeableName , Writeable .Reader <? extends InternalAggregation > resultReader ) {
205
+ resultReaders .put (writeableName , resultReader );
206
+ return this ;
207
+ }
208
+
209
+ /**
210
+ * Get the readers that must be registered for this aggregation's results.
211
+ */
212
+ public Map <String , Writeable .Reader <? extends InternalAggregation >> getResultReaders () {
213
+ return resultReaders ;
214
+ }
215
+ }
216
+
217
+ /**
218
+ * Specification for a {@link PipelineAggregator}.
219
+ */
220
+ public static class PipelineAggregationSpec extends SearchExtensionSpec <PipelineAggregationBuilder , PipelineAggregator .Parser > {
221
+ private final Map <String , Writeable .Reader <? extends InternalAggregation >> resultReaders = new TreeMap <>();
222
+ private final Writeable .Reader <? extends PipelineAggregator > aggregatorReader ;
223
+
224
+ /**
225
+ * Specification of a {@link PipelineAggregator}.
226
+ *
227
+ * @param name holds the names by which this aggregation might be parsed. The {@link ParseField#getPreferredName()} is special as it
228
+ * is the name by under which the readers are registered. So it is the name that the {@link PipelineAggregationBuilder} and
229
+ * {@link PipelineAggregator} should return from {@link NamedWriteable#getWriteableName()}.
230
+ * @param builderReader the reader registered for this aggregation's builder. Typically a reference to a constructor that takes a
231
+ * {@link StreamInput}
232
+ * @param aggregatorReader reads the {@link PipelineAggregator} from a stream
233
+ * @param parser reads the aggregation builder from XContent
234
+ */
235
+ public PipelineAggregationSpec (ParseField name ,
236
+ Writeable .Reader <? extends PipelineAggregationBuilder > builderReader ,
237
+ Writeable .Reader <? extends PipelineAggregator > aggregatorReader ,
238
+ PipelineAggregator .Parser parser ) {
239
+ super (name , builderReader , parser );
240
+ this .aggregatorReader = aggregatorReader ;
241
+ }
242
+
243
+ /**
244
+ * Specification of a {@link PipelineAggregator}.
245
+ *
246
+ * @param name name by which this aggregation might be parsed or deserialized. Make sure it is the name that the
247
+ * {@link PipelineAggregationBuilder} and {@link PipelineAggregator} should return from
248
+ * {@link NamedWriteable#getWriteableName()}.
249
+ * @param builderReader the reader registered for this aggregation's builder. Typically a reference to a constructor that takes a
250
+ * {@link StreamInput}
251
+ * @param aggregatorReader reads the {@link PipelineAggregator} from a stream
252
+ * @param parser reads the aggregation builder from XContent
253
+ */
254
+ public PipelineAggregationSpec (String name ,
255
+ Writeable .Reader <? extends PipelineAggregationBuilder > builderReader ,
256
+ Writeable .Reader <? extends PipelineAggregator > aggregatorReader ,
257
+ PipelineAggregator .Parser parser ) {
258
+ super (name , builderReader , parser );
259
+ this .aggregatorReader = aggregatorReader ;
260
+ }
261
+
262
+ /**
263
+ * Add a reader for the shard level results of the aggregation with {@linkplain #getName()}'s {@link ParseField#getPreferredName()}
264
+ * as the {@link NamedWriteable#getWriteableName()}.
265
+ */
266
+ public PipelineAggregationSpec addResultReader (Writeable .Reader <? extends InternalAggregation > resultReader ) {
267
+ return addResultReader (getName ().getPreferredName (), resultReader );
268
+ }
269
+
270
+ /**
271
+ * Add a reader for the shard level results of the aggregation.
272
+ */
273
+ public PipelineAggregationSpec addResultReader (String writeableName , Writeable .Reader <? extends InternalAggregation > resultReader ) {
274
+ resultReaders .put (writeableName , resultReader );
275
+ return this ;
276
+ }
277
+
278
+ /**
279
+ * The reader for the {@link PipelineAggregator}.
280
+ */
281
+ public Writeable .Reader <? extends PipelineAggregator > getAggregatorReader () {
282
+ return aggregatorReader ;
283
+ }
284
+
285
+ /**
286
+ * Get the readers that must be registered for this aggregation's results.
287
+ */
288
+ public Map <String , Writeable .Reader <? extends InternalAggregation >> getResultReaders () {
289
+ return resultReaders ;
290
+ }
291
+ }
292
+
142
293
143
294
/**
144
295
* Specification of search time behavior extension like a custom {@link MovAvgModel} or {@link ScoreFunction}.
@@ -150,7 +301,7 @@ public QuerySpec(String name, Reader<T> reader, QueryParser<T> parser) {
150
301
*/
151
302
class SearchExtensionSpec <W extends NamedWriteable , P > {
152
303
private final ParseField name ;
153
- private final Writeable .Reader <W > reader ;
304
+ private final Writeable .Reader <? extends W > reader ;
154
305
private final P parser ;
155
306
156
307
/**
@@ -162,7 +313,7 @@ class SearchExtensionSpec<W extends NamedWriteable, P> {
162
313
* @param reader reader that reads the behavior from the internode protocol
163
314
* @param parser parser that read the behavior from a REST request
164
315
*/
165
- public SearchExtensionSpec (ParseField name , Writeable .Reader <W > reader , P parser ) {
316
+ public SearchExtensionSpec (ParseField name , Writeable .Reader <? extends W > reader , P parser ) {
166
317
this .name = name ;
167
318
this .reader = reader ;
168
319
this .parser = parser ;
@@ -176,7 +327,7 @@ public SearchExtensionSpec(ParseField name, Writeable.Reader<W> reader, P parser
176
327
* @param reader reader that reads the behavior from the internode protocol
177
328
* @param parser parser that read the behavior from a REST request
178
329
*/
179
- public SearchExtensionSpec (String name , Writeable .Reader <W > reader , P parser ) {
330
+ public SearchExtensionSpec (String name , Writeable .Reader <? extends W > reader , P parser ) {
180
331
this (new ParseField (name ), reader , parser );
181
332
}
182
333
@@ -190,7 +341,7 @@ public ParseField getName() {
190
341
/**
191
342
* The reader responsible for reading the behavior from the internode protocol.
192
343
*/
193
- public Writeable .Reader <W > getReader () {
344
+ public Writeable .Reader <? extends W > getReader () {
194
345
return reader ;
195
346
}
196
347
0 commit comments