17
17
import org .elasticsearch .common .Strings ;
18
18
import org .elasticsearch .common .io .stream .StreamInput ;
19
19
import org .elasticsearch .common .io .stream .StreamOutput ;
20
- import org .elasticsearch .common .util .CollectionUtils ;
21
20
import org .elasticsearch .core .Nullable ;
22
21
import org .elasticsearch .core .TimeValue ;
23
22
import org .elasticsearch .index .mapper .SourceLoader ;
24
23
import org .elasticsearch .index .query .QueryRewriteContext ;
25
24
import org .elasticsearch .index .query .Rewriteable ;
26
25
import org .elasticsearch .search .Scroll ;
27
- import org .elasticsearch .search .SearchService ;
28
26
import org .elasticsearch .search .builder .PointInTimeBuilder ;
29
27
import org .elasticsearch .search .builder .SearchSourceBuilder ;
30
28
import org .elasticsearch .search .internal .SearchContext ;
31
- import org .elasticsearch .search .rescore .RescorerBuilder ;
32
29
import org .elasticsearch .search .sort .FieldSortBuilder ;
33
- import org .elasticsearch .search .sort .ShardDocSortField ;
34
30
import org .elasticsearch .search .sort .SortBuilder ;
35
31
import org .elasticsearch .search .sort .SortBuilders ;
36
32
import org .elasticsearch .tasks .TaskId ;
@@ -324,124 +320,15 @@ public void writeTo(StreamOutput out) throws IOException {
324
320
public ActionRequestValidationException validate () {
325
321
ActionRequestValidationException validationException = null ;
326
322
boolean scroll = scroll () != null ;
323
+
324
+ if (source != null ) {
325
+ validationException = source .validate (validationException , scroll );
326
+ }
327
327
if (scroll ) {
328
- if (source != null ) {
329
- if (source .trackTotalHitsUpTo () != null && source .trackTotalHitsUpTo () != SearchContext .TRACK_TOTAL_HITS_ACCURATE ) {
330
- validationException = addValidationError (
331
- "disabling [track_total_hits] is not allowed in a scroll context" ,
332
- validationException
333
- );
334
- }
335
- if (source .from () > 0 ) {
336
- validationException = addValidationError ("using [from] is not allowed in a scroll context" , validationException );
337
- }
338
- if (source .size () == 0 ) {
339
- validationException = addValidationError ("[size] cannot be [0] in a scroll context" , validationException );
340
- }
341
- if (source .rescores () != null && source .rescores ().isEmpty () == false ) {
342
- validationException = addValidationError ("using [rescore] is not allowed in a scroll context" , validationException );
343
- }
344
- if (CollectionUtils .isEmpty (source .searchAfter ()) == false ) {
345
- validationException = addValidationError ("[search_after] cannot be used in a scroll context" , validationException );
346
- }
347
- if (source .collapse () != null ) {
348
- validationException = addValidationError ("cannot use `collapse` in a scroll context" , validationException );
349
- }
350
- }
351
328
if (requestCache != null && requestCache ) {
352
329
validationException = addValidationError ("[request_cache] cannot be used in a scroll context" , validationException );
353
330
}
354
331
}
355
- if (source != null ) {
356
- if (source .slice () != null ) {
357
- if (source .pointInTimeBuilder () == null && (scroll == false )) {
358
- validationException = addValidationError (
359
- "[slice] can only be used with [scroll] or [point-in-time] requests" ,
360
- validationException
361
- );
362
- }
363
- }
364
- if (source .from () > 0 && CollectionUtils .isEmpty (source .searchAfter ()) == false ) {
365
- validationException = addValidationError (
366
- "[from] parameter must be set to 0 when [search_after] is used" ,
367
- validationException
368
- );
369
- }
370
- if (source .storedFields () != null ) {
371
- if (source .storedFields ().fetchFields () == false ) {
372
- if (source .fetchSource () != null && source .fetchSource ().fetchSource ()) {
373
- validationException = addValidationError (
374
- "[stored_fields] cannot be disabled if [_source] is requested" ,
375
- validationException
376
- );
377
- }
378
- if (source .fetchFields () != null ) {
379
- validationException = addValidationError (
380
- "[stored_fields] cannot be disabled when using the [fields] option" ,
381
- validationException
382
- );
383
- }
384
-
385
- }
386
- }
387
- if (source .subSearches ().size () >= 2 && source .rankBuilder () == null ) {
388
- validationException = addValidationError ("[sub_searches] requires [rank]" , validationException );
389
- }
390
- if (source .aggregations () != null ) {
391
- validationException = source .aggregations ().validate (validationException );
392
- }
393
- if (source .rankBuilder () != null ) {
394
- int size = source .size () == -1 ? SearchService .DEFAULT_SIZE : source .size ();
395
- if (size == 0 ) {
396
- validationException = addValidationError ("[rank] requires [size] greater than [0]" , validationException );
397
- }
398
- if (size > source .rankBuilder ().rankWindowSize ()) {
399
- validationException = addValidationError (
400
- "[rank] requires [rank_window_size: "
401
- + source .rankBuilder ().rankWindowSize ()
402
- + "]"
403
- + " be greater than or equal to [size: "
404
- + size
405
- + "]" ,
406
- validationException
407
- );
408
- }
409
- int queryCount = source .subSearches ().size () + source .knnSearch ().size ();
410
- if (source .rankBuilder ().isCompoundBuilder () && queryCount < 2 ) {
411
- validationException = addValidationError (
412
- "[rank] requires a minimum of [2] result sets using a combination of sub searches and/or knn searches" ,
413
- validationException
414
- );
415
- }
416
- if (scroll ) {
417
- validationException = addValidationError ("[rank] cannot be used in a scroll context" , validationException );
418
- }
419
- if (source .rescores () != null && source .rescores ().isEmpty () == false ) {
420
- validationException = addValidationError ("[rank] cannot be used with [rescore]" , validationException );
421
- }
422
- if (source .sorts () != null && source .sorts ().isEmpty () == false ) {
423
- validationException = addValidationError ("[rank] cannot be used with [sort]" , validationException );
424
- }
425
- if (source .collapse () != null ) {
426
- validationException = addValidationError ("[rank] cannot be used with [collapse]" , validationException );
427
- }
428
- if (source .suggest () != null && source .suggest ().getSuggestions ().isEmpty () == false ) {
429
- validationException = addValidationError ("[rank] cannot be used with [suggest]" , validationException );
430
- }
431
- if (source .highlighter () != null ) {
432
- validationException = addValidationError ("[rank] cannot be used with [highlighter]" , validationException );
433
- }
434
- if (source .pointInTimeBuilder () != null ) {
435
- validationException = addValidationError ("[rank] cannot be used with [point in time]" , validationException );
436
- }
437
- }
438
- if (source .rescores () != null ) {
439
- for (@ SuppressWarnings ("rawtypes" )
440
- RescorerBuilder rescoreBuilder : source .rescores ()) {
441
- validationException = rescoreBuilder .validate (this , validationException );
442
- }
443
- }
444
- }
445
332
if (pointInTimeBuilder () != null ) {
446
333
if (scroll ) {
447
334
validationException = addValidationError ("using [point in time] is not allowed in a scroll context" , validationException );
@@ -461,16 +348,6 @@ public ActionRequestValidationException validate() {
461
348
if (preference () != null ) {
462
349
validationException = addValidationError ("[preference] cannot be used with point in time" , validationException );
463
350
}
464
- } else if (source != null && source .sorts () != null ) {
465
- for (SortBuilder <?> sortBuilder : source .sorts ()) {
466
- if (sortBuilder instanceof FieldSortBuilder
467
- && ShardDocSortField .NAME .equals (((FieldSortBuilder ) sortBuilder ).getFieldName ())) {
468
- validationException = addValidationError (
469
- "[" + FieldSortBuilder .SHARD_DOC_FIELD_NAME + "] sort field cannot be used without [point in time]" ,
470
- validationException
471
- );
472
- }
473
- }
474
351
}
475
352
if (minCompatibleShardNode () != null ) {
476
353
if (isCcsMinimizeRoundtrips ()) {
0 commit comments