diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregationBuilder.java index 9ba4b2210fa..4f00a49a1d9 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregationBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregationBuilder.java @@ -98,7 +98,7 @@ public class GeoGridAggregationBuilder extends ValuesSourceAggregationBuilder -1) { + builder.field(GeoHashGridParams.FIELD_SHARD_SIZE.getPreferredName(), shardSize); + } return builder; } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsAggregationBuilder.java index 64a9c607729..e3886bee563 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsAggregationBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsAggregationBuilder.java @@ -113,8 +113,8 @@ public class SignificantTermsAggregationBuilder extends ValuesSourceAggregationB * (defaults to 10) */ public SignificantTermsAggregationBuilder size(int size) { - if (size < 0) { - throw new IllegalArgumentException("[size] must be greater than or equal to 0. Found [" + size + "] in [" + name + "]"); + if (size <= 0) { + throw new IllegalArgumentException("[size] must be greater than 0. Found [" + size + "] in [" + name + "]"); } bucketCountThresholds.setRequiredSize(size); return this; @@ -127,9 +127,9 @@ public class SignificantTermsAggregationBuilder extends ValuesSourceAggregationB * results are. */ public SignificantTermsAggregationBuilder shardSize(int shardSize) { - if (shardSize < 0) { + if (shardSize <= 0) { throw new IllegalArgumentException( - "[shardSize] must be greater than or equal to 0. Found [" + shardSize + "] in [" + name + "]"); + "[shardSize] must be greater than 0. Found [" + shardSize + "] in [" + name + "]"); } bucketCountThresholds.setShardSize(shardSize); return this; diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregationBuilder.java index f4cb133c499..1dd59edf6d9 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregationBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregationBuilder.java @@ -110,8 +110,8 @@ public class TermsAggregationBuilder extends ValuesSourceAggregationBuilder client() .prepareSearch("idx").setTypes("high_card_type").addAggregation(terms("terms").field(SINGLE_VALUED_FIELD_NAME) .minDocCount(randomInt(1)).size(0).collectMode(randomFrom(SubAggCollectionMode.values()))) .execute().actionGet()); - assertThat(exception.getDetailedMessage(), - containsString("parameters [required_size] and [shard_size] must be >0 in terms aggregation.")); + assertThat(exception.getMessage(), containsString("[size] must be greater than 0. Found [0] in [terms]")); } public void testSingleValueField() throws Exception { @@ -588,7 +587,7 @@ public class DoubleTermsTests extends AbstractTermsTestCase { SearchResponse response = client().prepareSearch("idx_unmapped").setTypes("type") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) - .size(randomInt(5)) + .size(randomIntBetween(1, 5)) .collectMode(randomFrom(SubAggCollectionMode.values()))) .execute().actionGet(); diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/LongTermsTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/LongTermsTests.java index dc3fea592a2..fa049429a3a 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/LongTermsTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/LongTermsTests.java @@ -238,7 +238,7 @@ public class LongTermsTests extends AbstractTermsTestCase { // the main purpose of this test is to make sure we're not allocating 2GB of memory per shard public void testSizeIsZero() { - ElasticsearchException exception = expectThrows(ElasticsearchException.class, + IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> client().prepareSearch("idx").setTypes("high_card_type") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) @@ -246,8 +246,7 @@ public class LongTermsTests extends AbstractTermsTestCase { .minDocCount(randomInt(1)) .size(0)) .execute().actionGet()); - assertThat(exception.getDetailedMessage(), - containsString("parameters [required_size] and [shard_size] must be >0 in terms aggregation.")); + assertThat(exception.getMessage(), containsString("[size] must be greater than 0. Found [0] in [terms]")); } public void testSingleValueField() throws Exception { @@ -593,7 +592,7 @@ public class LongTermsTests extends AbstractTermsTestCase { SearchResponse response = client().prepareSearch("idx_unmapped").setTypes("type") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) - .size(randomInt(5)) + .size(randomIntBetween(1, 5)) .collectMode(randomFrom(SubAggCollectionMode.values()))) .execute().actionGet(); diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/StringTermsTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/StringTermsTests.java index aa31ae2a118..b098db154da 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/StringTermsTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/StringTermsTests.java @@ -203,15 +203,14 @@ public class StringTermsTests extends AbstractTermsTestCase { // the main purpose of this test is to make sure we're not allocating 2GB of memory per shard public void testSizeIsZero() { final int minDocCount = randomInt(1); - ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> client() + IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> client() .prepareSearch("idx") .setTypes("high_card_type") .addAggregation( terms("terms").executionHint(randomExecutionHint()).field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())).minDocCount(minDocCount).size(0)).execute() .actionGet()); - assertThat(exception.getDetailedMessage(), - containsString("parameters [required_size] and [shard_size] must be >0 in terms aggregation.")); + assertThat(exception.getMessage(), containsString("[size] must be greater than 0. Found [0] in [terms]")); } public void testSingleValueField() throws Exception { @@ -756,7 +755,7 @@ public class StringTermsTests extends AbstractTermsTestCase { .prepareSearch("idx_unmapped") .setTypes("type") .addAggregation( - terms("terms").executionHint(randomExecutionHint()).size(randomInt(5)).field(SINGLE_VALUED_FIELD_NAME) + terms("terms").executionHint(randomExecutionHint()).size(randomIntBetween(1, 5)).field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values()))).execute().actionGet(); assertSearchResponse(response);