Skip to content

Commit e135bda

Browse files
authored
Read closing brace of extended stats aggregation (#4118)
Relates: #4109 This commit fixes an issue with extended stats aggregation parsing whereby the closing brace of std_deviation_bounds_as_string is not read when skipping over the object, leading to the reader exiting at this point, resulting in any subsequent aggregations from not being read from the JSON response and added to SearchResponse.Aggregations.
1 parent f550f73 commit e135bda

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/Nest/Aggregations/AggregateJsonConverter.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,11 @@ private IAggregate GetExtendedStatsAggregate(StatsAggregate statsMetric, JsonRea
413413
// std_deviation_bounds is an object, so we need to skip its properties
414414
if (((string)reader.Value).Equals(Parser.StdDeviationBoundsAsString))
415415
{
416-
reader.Read();
417-
reader.Read();
418-
reader.Read();
419-
reader.Read();
416+
reader.Read(); // move to {
417+
reader.Read(); // move to "upper"
418+
reader.Read(); // move to upper date value
419+
reader.Read(); // move to "lower"
420+
reader.Read(); // move to lower date value. Subsequent 2 reads will read closing "std_deviation_bounds_as_string" } and next token
420421
}
421422
reader.Read();
422423
reader.Read();

src/Tests/Tests.Reproduce/GitHubIssue4103.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ public void CanDeserializeExtendedStats()
5151
""upper"": ""2019-09-26T20:05:53.344Z"",
5252
""lower"": ""2019-09-26T17:56:16.529Z""
5353
}
54-
}
54+
},
55+
""sum"" : {
56+
""value"": 40
57+
}
5558
}
5659
}";
5760

@@ -66,6 +69,8 @@ public void CanDeserializeExtendedStats()
6669

6770
var response = client.Search<object>(s => s.AllIndices());
6871

72+
response.Aggregations.Count.Should().Be(2);
73+
6974
var extendedStats = response.Aggregations.ExtendedStats("1");
7075
extendedStats.Should().NotBeNull();
7176
extendedStats.Count.Should().Be(3);
@@ -79,6 +84,10 @@ public void CanDeserializeExtendedStats()
7984
extendedStats.StdDeviationBounds.Should().NotBeNull();
8085
extendedStats.StdDeviationBounds.Upper.Should().Be(1569528353344.9695);
8186
extendedStats.StdDeviationBounds.Lower.Should().Be(1569520576529.0305);
87+
88+
var sum = response.Aggregations.Sum("sum");
89+
sum.Should().NotBeNull();
90+
sum.Value.Should().Be(40);
8291
}
8392
}
8493
}

0 commit comments

Comments
 (0)