Skip to content

Commit 854f698

Browse files
author
Hendrik Muhs
authored
Percentiles aggregation: disallow specifying same percentile v… (#52257)
Disallow specifying the same percentile multiple times in percentiles aggregation Related: #51871
1 parent 451c341 commit 854f698

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

docs/reference/migration/migrate_8_0.asciidoc

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ See also <<release-highlights>> and <<es-release-notes>>.
1111

1212
coming[8.0.0]
1313

14+
* <<breaking_80_aggregations_changes>>
1415
* <<breaking_80_analysis_changes>>
1516
* <<breaking_80_allocation_changes>>
1617
* <<breaking_80_breaker_changes>>
@@ -63,6 +64,7 @@ is replaced with a new endpoint that does not contain `_xpack`. As an example,
6364

6465
// end::notable-breaking-changes[]
6566

67+
include::migrate_8_0/aggregations.asciidoc[]
6668
include::migrate_8_0/analysis.asciidoc[]
6769
include::migrate_8_0/allocation.asciidoc[]
6870
include::migrate_8_0/breaker.asciidoc[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[float]
2+
[[breaking_80_aggregations_changes]]
3+
=== Aggregations changes
4+
5+
//NOTE: The notable-breaking-changes tagged regions are re-used in the
6+
//Installation and Upgrade Guide
7+
8+
//tag::notable-breaking-changes[]
9+
[discrete]
10+
[[percentile-duplication]]
11+
==== Duplicate values no longer supported in percentiles aggregation
12+
13+
If you specify the `percents` parameter with the
14+
<<search-aggregations-metrics-percentile-aggregation,percentiles aggregation>>,
15+
its values must be unique. Otherwise, an exception occurs.
16+
17+
// end::notable-breaking-changes[]

docs/reference/release-notes/8.0.0-alpha1.asciidoc

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@
44
The changes listed below have been released for the first time in {es}
55
8.0.0-alpha1.
66

7-
coming[8.0.0]
7+
[[breaking-8.0.0-alpha1]]
8+
[float]
9+
=== Breaking changes
10+
11+
Aggregations::
12+
* Disallow specifying the same percentile multiple times in percentiles aggregation {pull}52257[#52257]
813

14+
coming[8.0.0]

server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentilesAggregationBuilder.java

+6
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,17 @@ private static double[] validatePercentiles(double[] percents, String aggName) {
9999
throw new IllegalArgumentException("[percents] must not be empty: [" + aggName + "]");
100100
}
101101
double[] sortedPercents = Arrays.copyOf(percents, percents.length);
102+
double previousPercent = -1.0;
102103
Arrays.sort(sortedPercents);
103104
for (double percent : sortedPercents) {
104105
if (percent < 0.0 || percent > 100.0) {
105106
throw new IllegalArgumentException("percent must be in [0,100], got [" + percent + "]: [" + aggName + "]");
106107
}
108+
109+
if (percent == previousPercent) {
110+
throw new IllegalArgumentException("percent [" + percent + "] has been specified twice: [" + aggName + "]");
111+
}
112+
previousPercent = percent;
107113
}
108114
return sortedPercents;
109115
}

server/src/test/java/org/elasticsearch/search/aggregations/metrics/PercentilesTests.java

+6
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ public void testOutOfRangePercentilesThrows() throws IOException {
7878
assertEquals("percent must be in [0,100], got [104.0]: [testAgg]", ex.getMessage());
7979
}
8080

81+
public void testDuplicatePercentilesThrows() throws IOException {
82+
PercentilesAggregationBuilder builder = new PercentilesAggregationBuilder("testAgg");
83+
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> builder.percentiles(5, 42, 10, 99, 42, 87));
84+
assertEquals("percent [42.0] has been specified twice: [testAgg]", ex.getMessage());
85+
}
86+
8187
public void testExceptionMultipleMethods() throws IOException {
8288
final String illegalAgg = "{\n" +
8389
" \"percentiles\": {\n" +

0 commit comments

Comments
 (0)