Skip to content

Commit adafd85

Browse files
committed
fix overal bg_count now gets returned for sig_terms
1 parent 98bf770 commit adafd85

File tree

6 files changed

+16
-1
lines changed

6 files changed

+16
-1
lines changed

src/Nest/Aggregations/AggregateJsonConverter.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ private static class Parser
3333
public const string DocCountErrorUpperBound = "doc_count_error_upper_bound";
3434
public const string Count = "count";
3535
public const string DocCount = "doc_count";
36+
public const string BgCount = "bg_count";
3637
public const string Bounds = "bounds";
3738
public const string Hits = "hits";
3839
public const string Location = "location";
@@ -301,11 +302,20 @@ private IAggregate GetSingleBucketAggregate(JsonReader reader, JsonSerializer se
301302
var docCount = (reader.Value as long?).GetValueOrDefault(0);
302303
var bucket = new SingleBucketAggregate {DocCount = docCount};
303304
reader.Read();
305+
long? bgCount = null;
306+
if ((string)reader.Value == Parser.BgCount)
307+
{
308+
reader.Read();
309+
bgCount = (reader.Value as long?).GetValueOrDefault(0);
310+
reader.Read();
311+
312+
}
304313
if (reader.TokenType == JsonToken.PropertyName && (string) reader.Value == Parser.Buckets)
305314
{
306315
var b = this.GetMultiBucketAggregate(reader, serializer) as BucketAggregate;
307316
return new BucketAggregate
308317
{
318+
BgCount = bgCount,
309319
DocCount = docCount,
310320
Items = b.Items
311321
};

src/Nest/Aggregations/AggregationsHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public SignificantTermsAggregate SignificantTerms(string key)
112112
? null
113113
: new SignificantTermsAggregate
114114
{
115+
BgCount = bucket.BgCount,
115116
DocCount = bucket.DocCount,
116117
Buckets = bucket.Items.OfType<SignificantTermsBucket>().ToList(),
117118
Meta = bucket.Meta

src/Nest/Aggregations/Bucket/BucketAggregate.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ public class BucketAggregate : IAggregate
3636
public long? SumOtherDocCount { get; set; }
3737
public IReadOnlyDictionary<string, object> Meta { get; set; } = EmptyReadOnly<string, object>.Dictionary;
3838
public long DocCount { get; set; }
39+
public long? BgCount { get; set; }
3940
}
4041
}

src/Nest/Aggregations/Bucket/SignificantTerms/SignificantTermsAggregate.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ public SignificantTermsAggregate() { }
1111
public SignificantTermsAggregate(IDictionary<string, IAggregate> aggregations) : base(aggregations) { }
1212

1313
public long DocCount { get; set; }
14+
public long? BgCount { get; set; }
1415
}
1516
}

src/Tests/Aggregations/Bucket/Sampler/SamplerAggregationUsageTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ protected override void ExpectResponse(ISearchResponse<Project> response)
6969
sample.Should().NotBeNull();
7070
var sigTags = sample.SignificantTerms("significant_names");
7171
sigTags.Should().NotBeNull();
72+
sigTags.BgCount.Should().BeGreaterThan(0);
73+
sigTags.DocCount.Should().BeGreaterThan(0);
7274
}
7375
}
7476
}

src/Tests/tests.default.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# tracked by git).
66

77
# mode either u (unit test), i (integration test) or m (mixed mode)
8-
mode: u
8+
mode: i
99
# the elasticsearch version that should be started
1010
# Can be a snapshot version of sonatype or "latest" to get the latest snapshot of sonatype
1111
elasticsearch_version: 5.5.0

0 commit comments

Comments
 (0)