@@ -426,36 +426,56 @@ public Builder<Context> client(ElasticsearchClient client) {
426
426
/**
427
427
* Sets when to flush a new bulk request based on the number of operations currently added. Defaults to
428
428
* {@code 1000}. Can be set to {@code -1} to disable it.
429
+ *
430
+ * @throws IllegalArgumentException if less than -1.
429
431
*/
430
432
public Builder <Context > maxOperations (int count ) {
433
+ if (count < -1 ) {
434
+ throw new IllegalArgumentException ("Max operations should be at least -1" );
435
+ }
431
436
this .bulkOperations = count ;
432
437
return this ;
433
438
}
434
439
435
440
/**
436
441
* Sets when to flush a new bulk request based on the size in bytes of actions currently added. A request is sent
437
442
* once that size has been exceeded. Defaults to 5 megabytes. Can be set to {@code -1} to disable it.
443
+ *
444
+ * @throws IllegalArgumentException if less than -1.
438
445
*/
439
446
public Builder <Context > maxSize (long bytes ) {
447
+ if (bytes < -1 ) {
448
+ throw new IllegalArgumentException ("Max size should be at least -1" );
449
+ }
440
450
this .bulkSize = bytes ;
441
451
return this ;
442
452
}
443
453
444
454
/**
445
- * Sets the number of concurrent requests allowed to be executed. A value of 1 means 1 concurrent request is allowed to be executed
455
+ * Sets the number of concurrent requests allowed to be executed. A value of 1 means 1 request is allowed to be executed
446
456
* while accumulating new bulk requests. Defaults to {@code 1}.
457
+ *
458
+ * @throws IllegalArgumentException if less than 1.
447
459
*/
448
460
public Builder <Context > maxConcurrentRequests (int max ) {
461
+ if (max < 1 ) {
462
+ throw new IllegalArgumentException ("Max concurrent request should be at least 1" );
463
+ }
449
464
this .maxConcurrentRequests = max ;
450
465
return this ;
451
466
}
452
467
453
468
/**
454
469
* Sets an interval flushing any bulk actions pending if the interval passes. Defaults to not set.
455
470
* <p>
456
- * Flushing is still subject to the maximum number of requests set with {@link #maxConcurrentRequests}.
471
+ * Flushing is still subject to the maximum number of requests set with {@link #maxConcurrentRequests}.
472
+ *
473
+ * @throws IllegalArgumentException if not a positive duration.
457
474
*/
458
475
public Builder <Context > flushInterval (long value , TimeUnit unit ) {
476
+ if (value < 0 ) {
477
+ throw new IllegalArgumentException ("Duration should be positive" );
478
+ }
459
479
this .flushIntervalMillis = unit .toMillis (value );
460
480
return this ;
461
481
}
@@ -497,6 +517,13 @@ public Builder<Context> globalSettings(Function<BulkRequest.Builder, BulkRequest
497
517
498
518
@ Override
499
519
public BulkIngester <Context > build () {
520
+ // Ensure some chunking criteria are defined
521
+ boolean hasCriteria = this .bulkOperations >= 0 || this .bulkSize >= 0 || this .flushIntervalMillis != null ;
522
+
523
+ if (!hasCriteria ) {
524
+ throw new IllegalStateException ("No bulk operation chunking criteria have been set." );
525
+ }
526
+
500
527
return new BulkIngester <>(this );
501
528
}
502
529
}
0 commit comments