@@ -426,36 +426,56 @@ public Builder<Context> client(ElasticsearchClient client) {
426426 /**
427427 * Sets when to flush a new bulk request based on the number of operations currently added. Defaults to
428428 * {@code 1000}. Can be set to {@code -1} to disable it.
429+ *
430+ * @throws IllegalArgumentException if less than -1.
429431 */
430432 public Builder <Context > maxOperations (int count ) {
433+ if (count < -1 ) {
434+ throw new IllegalArgumentException ("Max operations should be at least -1" );
435+ }
431436 this .bulkOperations = count ;
432437 return this ;
433438 }
434439
435440 /**
436441 * Sets when to flush a new bulk request based on the size in bytes of actions currently added. A request is sent
437442 * 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.
438445 */
439446 public Builder <Context > maxSize (long bytes ) {
447+ if (bytes < -1 ) {
448+ throw new IllegalArgumentException ("Max size should be at least -1" );
449+ }
440450 this .bulkSize = bytes ;
441451 return this ;
442452 }
443453
444454 /**
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
446456 * while accumulating new bulk requests. Defaults to {@code 1}.
457+ *
458+ * @throws IllegalArgumentException if less than 1.
447459 */
448460 public Builder <Context > maxConcurrentRequests (int max ) {
461+ if (max < 1 ) {
462+ throw new IllegalArgumentException ("Max concurrent request should be at least 1" );
463+ }
449464 this .maxConcurrentRequests = max ;
450465 return this ;
451466 }
452467
453468 /**
454469 * Sets an interval flushing any bulk actions pending if the interval passes. Defaults to not set.
455470 * <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.
457474 */
458475 public Builder <Context > flushInterval (long value , TimeUnit unit ) {
476+ if (value < 0 ) {
477+ throw new IllegalArgumentException ("Duration should be positive" );
478+ }
459479 this .flushIntervalMillis = unit .toMillis (value );
460480 return this ;
461481 }
@@ -497,6 +517,13 @@ public Builder<Context> globalSettings(Function<BulkRequest.Builder, BulkRequest
497517
498518 @ Override
499519 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+
500527 return new BulkIngester <>(this );
501528 }
502529 }
0 commit comments