Skip to content

Commit 5138c0c

Browse files
authored
Fix missing null values for std_deviation_bounds in ext. stats aggs (#58000)
Adds missing null values for std_deviation_bounds in extended stats aggs and improves null handling in parsed extended stats.
1 parent 1814b66 commit 5138c0c

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ protected XContentBuilder otherStatsToXContent(XContentBuilder builder, Params p
329329
{
330330
builder.nullField(Fields.UPPER);
331331
builder.nullField(Fields.LOWER);
332+
builder.nullField(Fields.UPPER_POPULATION);
333+
builder.nullField(Fields.LOWER_POPULATION);
334+
builder.nullField(Fields.UPPER_SAMPLING);
335+
builder.nullField(Fields.LOWER_SAMPLING);
332336
}
333337
builder.endObject();
334338
}

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,12 @@ public double getStdDeviationSampling() {
9595
}
9696

9797
private void setStdDeviationBounds(List<Double> bounds) {
98-
int i = 0;
99-
this.stdDeviationBoundUpper = bounds.get(i++);
100-
this.stdDeviationBoundLower = bounds.get(i++);
101-
this.stdDeviationBoundUpperPopulation = bounds.get(i++);
102-
this.stdDeviationBoundLowerPopulation = bounds.get(i++);
103-
this.stdDeviationBoundUpperSampling = bounds.get(i++);
104-
this.stdDeviationBoundLowerSampling = bounds.get(i);
105-
98+
this.stdDeviationBoundUpper = bounds.get(0);
99+
this.stdDeviationBoundLower = bounds.get(1);
100+
this.stdDeviationBoundUpperPopulation = bounds.get(2) == null ? 0 : bounds.get(2);
101+
this.stdDeviationBoundLowerPopulation = bounds.get(3) == null ? 0 : bounds.get(3);
102+
this.stdDeviationBoundUpperSampling = bounds.get(4) == null ? 0 : bounds.get(4);
103+
this.stdDeviationBoundLowerSampling = bounds.get(5) == null ? 0 : bounds.get(5);
106104
}
107105

108106
@Override
@@ -126,13 +124,20 @@ public double getStdDeviationBound(Bounds bound) {
126124
}
127125

128126
private void setStdDeviationBoundsAsString(List<String> boundsAsString) {
129-
int i = 0;
130-
this.valueAsString.put(Fields.STD_DEVIATION_BOUNDS_AS_STRING + "_upper", boundsAsString.get(i++));
131-
this.valueAsString.put(Fields.STD_DEVIATION_BOUNDS_AS_STRING + "_lower", boundsAsString.get(i++));
132-
this.valueAsString.put(Fields.STD_DEVIATION_BOUNDS_AS_STRING + "_upper_population", boundsAsString.get(i++));
133-
this.valueAsString.put(Fields.STD_DEVIATION_BOUNDS_AS_STRING + "_lower_population", boundsAsString.get(i++));
134-
this.valueAsString.put(Fields.STD_DEVIATION_BOUNDS_AS_STRING + "_upper_sampling", boundsAsString.get(i++));
135-
this.valueAsString.put(Fields.STD_DEVIATION_BOUNDS_AS_STRING + "_lower_sampling", boundsAsString.get(i));
127+
this.valueAsString.put(Fields.STD_DEVIATION_BOUNDS_AS_STRING + "_upper", boundsAsString.get(0));
128+
this.valueAsString.put(Fields.STD_DEVIATION_BOUNDS_AS_STRING + "_lower", boundsAsString.get(1));
129+
if (boundsAsString.get(2) != null) {
130+
this.valueAsString.put(Fields.STD_DEVIATION_BOUNDS_AS_STRING + "_upper_population", boundsAsString.get(2));
131+
}
132+
if (boundsAsString.get(3) != null) {
133+
this.valueAsString.put(Fields.STD_DEVIATION_BOUNDS_AS_STRING + "_lower_population", boundsAsString.get(3));
134+
}
135+
if (boundsAsString.get(4) != null) {
136+
this.valueAsString.put(Fields.STD_DEVIATION_BOUNDS_AS_STRING + "_upper_sampling", boundsAsString.get(4));
137+
}
138+
if (boundsAsString.get(5) != null) {
139+
this.valueAsString.put(Fields.STD_DEVIATION_BOUNDS_AS_STRING + "_lower_sampling", boundsAsString.get(5));
140+
}
136141
}
137142

138143
@Override

0 commit comments

Comments
 (0)