43
43
import org .elasticsearch .common .xcontent .XContentType ;
44
44
import org .elasticsearch .rest .BaseRestHandler ;
45
45
import org .elasticsearch .rest .BytesRestResponse ;
46
- import org .elasticsearch .rest .RestController ;
47
46
import org .elasticsearch .rest .RestRequest ;
48
47
import org .elasticsearch .rest .action .search .RestSearchAction ;
49
48
import org .elasticsearch .search .SearchHit ;
@@ -114,7 +113,6 @@ public static class ClusteringActionRequest extends ActionRequest implements Ind
114
113
public static String JSON_ALGORITHM = "algorithm" ;
115
114
public static String JSON_ATTRIBUTES = "attributes" ;
116
115
public static String JSON_SEARCH_REQUEST = "search_request" ;
117
- public static String JSON_INCLUDE_HITS = "include_hits" ;
118
116
public static String JSON_MAX_HITS = "max_hits" ;
119
117
public static String JSON_CREATE_UNGROUPED_CLUSTER = "create_ungrouped" ;
120
118
public static String JSON_LANGUAGE = "language" ;
@@ -143,6 +141,9 @@ public ClusteringActionRequest setSearchRequest(SearchRequest searchRequest) {
143
141
144
142
/**
145
143
* @see #setSearchRequest(SearchRequest)
144
+ *
145
+ * @param builder The search builder
146
+ * @return Returns same object for chaining.
146
147
*/
147
148
public ClusteringActionRequest setSearchRequest (SearchRequestBuilder builder ) {
148
149
return setSearchRequest (builder .request ());
@@ -192,6 +193,8 @@ public ClusteringActionRequest setQueryHint(String queryHint) {
192
193
193
194
/**
194
195
* @see #setQueryHint(String)
196
+ *
197
+ * @return Query hint
195
198
*/
196
199
public String getQueryHint () {
197
200
return queryHint ;
@@ -200,6 +203,9 @@ public String getQueryHint() {
200
203
/**
201
204
* Sets the identifier of the clustering algorithm to use. If <code>null</code>, the default
202
205
* algorithm will be used (depending on what's available).
206
+ *
207
+ * @param algorithm identifier of the clustering algorithm to use.
208
+ * @return Same object for chaining
203
209
*/
204
210
public ClusteringActionRequest setAlgorithm (String algorithm ) {
205
211
this .algorithm = algorithm ;
@@ -208,42 +214,21 @@ public ClusteringActionRequest setAlgorithm(String algorithm) {
208
214
209
215
/**
210
216
* @see #setAlgorithm
217
+ *
218
+ * @return The current algorithm to use for clustering
211
219
*/
212
220
public String getAlgorithm () {
213
221
return algorithm ;
214
222
}
215
223
216
- /**
217
- * @see #getIncludeHits
218
- * @deprecated Use {@link #setMaxHits} and set it to zero instead.
219
- */
220
- @ Deprecated ()
221
- public boolean getIncludeHits () {
222
- return maxHits > 0 ;
223
- }
224
-
225
- /**
226
- * Sets whether to include hits with clustering results. If only cluster labels
227
- * are needed the hits may be omitted to save bandwidth.
228
- *
229
- * @deprecated Use {@link #setMaxHits} instead.
230
- */
231
- @ Deprecated ()
232
- public ClusteringActionRequest setIncludeHits (boolean includeHits ) {
233
- if (includeHits ) {
234
- setMaxHits (Integer .MAX_VALUE );
235
- } else {
236
- setMaxHits (0 );
237
- }
238
- return this ;
239
- }
240
-
241
224
/**
242
225
* Sets the maximum number of hits to return with the response. Setting this
243
226
* value to zero will only return clusters, without any hits (can be used
244
227
* to save bandwidth if only cluster labels are needed).
245
228
* <p>
246
229
* Set to {@link Integer#MAX_VALUE} to include all the hits.
230
+ *
231
+ * @param maxHits Maximum hits
247
232
*/
248
233
public void setMaxHits (int maxHits ) {
249
234
assert maxHits >= 0 ;
@@ -253,6 +238,8 @@ public void setMaxHits(int maxHits) {
253
238
/**
254
239
* Sets {@link #setMaxHits(int)} from a string. An empty string or null means
255
240
* all hits should be included.
241
+ *
242
+ * @param value Maximum number of hits.
256
243
*/
257
244
public void setMaxHits (String value ) {
258
245
if (value == null || value .trim ().isEmpty ()) {
@@ -263,15 +250,18 @@ public void setMaxHits(String value) {
263
250
}
264
251
265
252
/**
266
- * Returns the maximum number of hits to be returned as part of the response.
267
- * If equal to {@link Integer#MAX_VALUE}, then all hits will be returned.
253
+ * @return Returns the maximum number of hits to be returned as part of the response. * If equal
254
+ * to {@link Integer#MAX_VALUE}, then all hits will be returned.
268
255
*/
269
256
public int getMaxHits () {
270
257
return maxHits ;
271
258
}
272
259
273
260
/**
274
261
* Sets a map of runtime override attributes for clustering algorithms.
262
+ *
263
+ * @param map Clustering attributes to use.
264
+ * @return Same object for chaining
275
265
*/
276
266
public ClusteringActionRequest setAttributes (Map <String , Object > map ) {
277
267
this .attributes = map ;
@@ -280,13 +270,19 @@ public ClusteringActionRequest setAttributes(Map<String, Object> map) {
280
270
281
271
/**
282
272
* @see #setAttributes(Map)
273
+ *
274
+ * @return Clustering algorithm attributes map
283
275
*/
284
276
public Map <String , Object > getAttributes () {
285
277
return attributes ;
286
278
}
287
279
288
280
/**
289
281
* Parses some {@link org.elasticsearch.common.xcontent.XContent} and fills in the request.
282
+ *
283
+ * @param source arg
284
+ * @param xContentType arg
285
+ * @param xContentRegistry arg
290
286
*/
291
287
@ SuppressWarnings ("unchecked" )
292
288
public void source (BytesReference source , XContentType xContentType , NamedXContentRegistry xContentRegistry ) {
@@ -345,12 +341,6 @@ public void source(BytesReference source, XContentType xContentType, NamedXConte
345
341
searchRequest .source (searchSourceBuilder );
346
342
}
347
343
348
- Object includeHits = asMap .get (JSON_INCLUDE_HITS );
349
- if (includeHits != null ) {
350
- LogManager .getLogger (getClass ()).warn ("Request used deprecated 'include_hits' parameter." );
351
- setIncludeHits (Boolean .parseBoolean (includeHits .toString ()));
352
- }
353
-
354
344
Object maxHits = asMap .get (JSON_MAX_HITS );
355
345
if (maxHits != null ) {
356
346
setMaxHits (maxHits .toString ());
@@ -381,6 +371,10 @@ private void parseFieldSpecs(Map<String, List<String>> fieldSpecs) {
381
371
* Map a hit's field to a logical section of a document to be clustered (title, content or URL).
382
372
*
383
373
* @see LogicalField
374
+ *
375
+ * @param fieldName field name
376
+ * @param logicalField logical field mapping.
377
+ * @return Same object for chaining
384
378
*/
385
379
public ClusteringActionRequest addFieldMapping (String fieldName , LogicalField logicalField ) {
386
380
fieldMapping .add (new FieldMappingSpec (fieldName , logicalField , FieldSource .FIELD ));
@@ -392,6 +386,10 @@ public ClusteringActionRequest addFieldMapping(String fieldName, LogicalField lo
392
386
* to a logical section of a document to be clustered (title, content or URL).
393
387
*
394
388
* @see LogicalField
389
+ *
390
+ * @param sourceFieldName field name
391
+ * @param logicalField logical field mapping.
392
+ * @return Same object for chaining
395
393
*/
396
394
public ClusteringActionRequest addSourceFieldMapping (String sourceFieldName , LogicalField logicalField ) {
397
395
fieldMapping .add (new FieldMappingSpec (sourceFieldName , logicalField , FieldSource .SOURCE ));
@@ -403,6 +401,10 @@ public ClusteringActionRequest addSourceFieldMapping(String sourceFieldName, Log
403
401
* of a document to be clustered. This may be used to decrease the amount of information
404
402
* passed to the clustering engine but also to "focus" the clustering engine on the context
405
403
* of the query.
404
+ *
405
+ * @param fieldName field name
406
+ * @param logicalField logical field mapping.
407
+ * @return Same object for chaining
406
408
*/
407
409
public ClusteringActionRequest addHighlightedFieldMapping (String fieldName , LogicalField logicalField ) {
408
410
fieldMapping .add (new FieldMappingSpec (fieldName , logicalField , FieldSource .HIGHLIGHT ));
@@ -413,6 +415,10 @@ public ClusteringActionRequest addHighlightedFieldMapping(String fieldName, Logi
413
415
* Add a (valid!) field mapping specification to a logical field.
414
416
*
415
417
* @see FieldSource
418
+ *
419
+ * @param fieldSpec field specification
420
+ * @param logicalField logical field mapping.
421
+ * @return Same object for chaining
416
422
*/
417
423
public ClusteringActionRequest addFieldMappingSpec (String fieldSpec , LogicalField logicalField ) {
418
424
FieldSource .ParsedFieldSource pfs = FieldSource .parseSpec (fieldSpec );
@@ -569,18 +575,6 @@ public ClusteringActionRequestBuilder setSource(BytesReference content,
569
575
return this ;
570
576
}
571
577
572
- /**
573
- * @deprecated Use {@link #setMaxHits} instead.
574
- */
575
- @ Deprecated ()
576
- public ClusteringActionRequestBuilder setIncludeHits (String includeHits ) {
577
- if (includeHits != null )
578
- super .request .setIncludeHits (Boolean .parseBoolean (includeHits ));
579
- else
580
- super .request .setIncludeHits (true );
581
- return this ;
582
- }
583
-
584
578
public ClusteringActionRequestBuilder setMaxHits (int maxHits ) {
585
579
super .request .setMaxHits (maxHits );
586
580
return this ;
@@ -910,9 +904,6 @@ public void onResponse(SearchResponse response) {
910
904
ClusteringActionResponse .Fields .Info .TOTAL_MILLIS ,
911
905
Long .toString (
912
906
TimeUnit .NANOSECONDS .toMillis (System .nanoTime () - tsSearchStart )));
913
- info .put (
914
- ClusteringActionResponse .Fields .Info .INCLUDE_HITS ,
915
- Boolean .toString (clusteringRequest .getIncludeHits ()));
916
907
info .put (
917
908
ClusteringActionResponse .Fields .Info .MAX_HITS ,
918
909
clusteringRequest .getMaxHits () == Integer .MAX_VALUE
@@ -1243,14 +1234,16 @@ public static class RestClusteringAction extends BaseRestHandler {
1243
1234
*/
1244
1235
public static String NAME = "_search_with_clusters" ;
1245
1236
1246
- public RestClusteringAction (RestController controller ) {
1247
- controller .registerHandler (POST , "/" + NAME , this );
1248
- controller .registerHandler (POST , "/{index}/" + NAME , this );
1249
- controller .registerHandler (POST , "/{index}/{type}/" + NAME , this );
1250
-
1251
- controller .registerHandler (GET , "/" + NAME , this );
1252
- controller .registerHandler (GET , "/{index}/" + NAME , this );
1253
- controller .registerHandler (GET , "/{index}/{type}/" + NAME , this );
1237
+ @ Override
1238
+ public List <Route > routes () {
1239
+ return Arrays .asList (
1240
+ new Route (POST , "/" + NAME ),
1241
+ new Route (POST , "/{index}/" + NAME ),
1242
+ new Route (POST , "/{index}/{type}/" + NAME ),
1243
+ new Route (GET , "/" + NAME ),
1244
+ new Route (GET , "/{index}/" + NAME ),
1245
+ new Route (GET , "/{index}/{type}/" + NAME )
1246
+ );
1254
1247
}
1255
1248
1256
1249
@ Override
@@ -1368,10 +1361,6 @@ private void fillFromGetRequest(
1368
1361
actionBuilder .setAlgorithm (request .param (ClusteringActionRequest .JSON_ALGORITHM ));
1369
1362
}
1370
1363
1371
- if (request .hasParam (ClusteringActionRequest .JSON_INCLUDE_HITS )) {
1372
- actionBuilder .setIncludeHits (request .param (ClusteringActionRequest .JSON_INCLUDE_HITS ));
1373
- }
1374
-
1375
1364
if (request .hasParam (ClusteringActionRequest .JSON_MAX_HITS )) {
1376
1365
actionBuilder .setMaxHits (request .param (ClusteringActionRequest .JSON_MAX_HITS ));
1377
1366
}
0 commit comments