diff --git a/docs/reference/migration/migrate_8_0.asciidoc b/docs/reference/migration/migrate_8_0.asciidoc index 4478b678a11f3..bf363ea30f858 100644 --- a/docs/reference/migration/migrate_8_0.asciidoc +++ b/docs/reference/migration/migrate_8_0.asciidoc @@ -11,6 +11,7 @@ See also <> and <>. coming[8.0.0] +* <> * <> * <> * <> @@ -63,6 +64,7 @@ is replaced with a new endpoint that does not contain `_xpack`. As an example, // end::notable-breaking-changes[] +include::migrate_8_0/aggregations.asciidoc[] include::migrate_8_0/analysis.asciidoc[] include::migrate_8_0/allocation.asciidoc[] include::migrate_8_0/breaker.asciidoc[] diff --git a/docs/reference/migration/migrate_8_0/aggregations.asciidoc b/docs/reference/migration/migrate_8_0/aggregations.asciidoc new file mode 100644 index 0000000000000..fd7c3affb15b0 --- /dev/null +++ b/docs/reference/migration/migrate_8_0/aggregations.asciidoc @@ -0,0 +1,17 @@ +[float] +[[breaking_80_aggregations_changes]] +=== Aggregations changes + +//NOTE: The notable-breaking-changes tagged regions are re-used in the +//Installation and Upgrade Guide + +//tag::notable-breaking-changes[] +[discrete] +[[percentile-duplication]] +==== Duplicate values no longer supported in percentiles aggregation + +If you specify the `percents` parameter with the +<>, +its values must be unique. Otherwise, an exception occurs. + +// end::notable-breaking-changes[] \ No newline at end of file diff --git a/docs/reference/release-notes/8.0.0-alpha1.asciidoc b/docs/reference/release-notes/8.0.0-alpha1.asciidoc index 4693221f629cf..239ffb0e3f94f 100644 --- a/docs/reference/release-notes/8.0.0-alpha1.asciidoc +++ b/docs/reference/release-notes/8.0.0-alpha1.asciidoc @@ -4,5 +4,11 @@ The changes listed below have been released for the first time in {es} 8.0.0-alpha1. -coming[8.0.0] +[[breaking-8.0.0-alpha1]] +[float] +=== Breaking changes + +Aggregations:: +* Disallow specifying the same percentile multiple times in percentiles aggregation {pull}52257[#52257] +coming[8.0.0] diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentilesAggregationBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentilesAggregationBuilder.java index 851304a4c63ce..ca6b13ac5a421 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentilesAggregationBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentilesAggregationBuilder.java @@ -99,11 +99,17 @@ private static double[] validatePercentiles(double[] percents, String aggName) { throw new IllegalArgumentException("[percents] must not be empty: [" + aggName + "]"); } double[] sortedPercents = Arrays.copyOf(percents, percents.length); + double previousPercent = -1.0; Arrays.sort(sortedPercents); for (double percent : sortedPercents) { if (percent < 0.0 || percent > 100.0) { throw new IllegalArgumentException("percent must be in [0,100], got [" + percent + "]: [" + aggName + "]"); } + + if (percent == previousPercent) { + throw new IllegalArgumentException("percent [" + percent + "] has been specified twice: [" + aggName + "]"); + } + previousPercent = percent; } return sortedPercents; } diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/PercentilesTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/PercentilesTests.java index c18fa664ffd99..5d1d9f1353d32 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/PercentilesTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/PercentilesTests.java @@ -78,6 +78,12 @@ public void testOutOfRangePercentilesThrows() throws IOException { assertEquals("percent must be in [0,100], got [104.0]: [testAgg]", ex.getMessage()); } + public void testDuplicatePercentilesThrows() throws IOException { + PercentilesAggregationBuilder builder = new PercentilesAggregationBuilder("testAgg"); + IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> builder.percentiles(5, 42, 10, 99, 42, 87)); + assertEquals("percent [42.0] has been specified twice: [testAgg]", ex.getMessage()); + } + public void testExceptionMultipleMethods() throws IOException { final String illegalAgg = "{\n" + " \"percentiles\": {\n" +