Skip to content

Commit 7ce1133

Browse files
authored
Handle empty aggregation (#3722)
Closes #3717
1 parent 4ebcca8 commit 7ce1133

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

src/Nest/Aggregations/AggregateFormatter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,11 @@ public IAggregate Deserialize(ref JsonReader reader, IJsonFormatterResolver form
8787
private IAggregate ReadAggregate(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
8888
{
8989
reader.ReadIsBeginObjectWithVerify();
90-
9190
IAggregate aggregate = null;
91+
92+
if (reader.ReadIsEndObject())
93+
return aggregate;
94+
9295
var propertyName = reader.ReadPropertyNameSegmentRaw();
9396
Dictionary<string, object> meta = null;
9497

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Text;
3+
using Elastic.Xunit.XunitPlumbing;
4+
using Elasticsearch.Net;
5+
using FluentAssertions;
6+
using Nest;
7+
8+
namespace Tests.Reproduce
9+
{
10+
public class GithubIssue3717
11+
{
12+
[U]
13+
public void CanDeserializeEmptyAggregation()
14+
{
15+
var json = @"{
16+
""took"" : 2,
17+
""timed_out"" : false,
18+
""_shards"" : {
19+
""total"" : 3,
20+
""successful"" : 3,
21+
""skipped"" : 0,
22+
""failed"" : 0
23+
},
24+
""hits"" : {
25+
""total"" : {
26+
""value"" : 10000,
27+
""relation"" : ""gte""
28+
},
29+
""max_score"" : null,
30+
""hits"" : [ ]
31+
},
32+
""aggregations"" : {
33+
""geo_bounds#viewport"" : { }
34+
}
35+
}";
36+
37+
var bytes = Encoding.UTF8.GetBytes(json);
38+
39+
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
40+
var connectionSettings = new ConnectionSettings(pool, new InMemoryConnection(bytes));
41+
var client = new ElasticClient(connectionSettings);
42+
43+
Func<SearchResponse<TestEntity>> response = () => client.Search<TestEntity>(s => s
44+
.Size(0)
45+
.Index("issue")
46+
.Aggregations(q => q
47+
.GeoBounds("viewport", t => t
48+
.Field(f => f.TestProperty)))
49+
);
50+
51+
response.Should().NotThrow();
52+
}
53+
54+
public class TestEntity {
55+
public string TestProperty { get; set; }
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)