Skip to content

Commit 8658956

Browse files
committed
Merge pull request #1206 from mausch/develop
Expose constructor with inner aggregation dictionary
2 parents 8c00ecb + 2f85641 commit 8658956

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
namespace Nest
1+
using System.Collections.Generic;
2+
namespace Nest
23
{
34
public abstract class BucketAggregationBase : AggregationsHelper , IBucketAggregation
4-
{
5-
5+
{
6+
protected BucketAggregationBase() { }
7+
protected BucketAggregationBase(IDictionary<string, IAggregation> aggregations) : base(aggregations) { }
68
}
79
}

src/Nest/Domain/Aggregations/SingleBucket.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
using Newtonsoft.Json;
1+
using Newtonsoft.Json;
2+
using System.Collections.Generic;
23

34
namespace Nest
45
{
56
public class SingleBucket : BucketAggregationBase
6-
{
7+
{
8+
public SingleBucket() { }
9+
10+
public SingleBucket(IDictionary<string, IAggregation> aggregations) : base(aggregations) { }
11+
712
[JsonProperty("doc_count")]
813
public long DocCount { get; set; }
914
}

src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@
396396
<Compile Include="Reproduce\Reproduce876Tests.cs" />
397397
<Compile Include="Reproduce\Reproduce926Tests.cs" />
398398
<Compile Include="Search\Aggregations\ScriptedMetricJson.cs" />
399+
<Compile Include="Search\Aggregations\SingleBucketAggregationTests.cs" />
399400
<Compile Include="Search\Failures\ShardFailureTests.cs" />
400401
<Compile Include="Search\Fields\FieldsTests.cs" />
401402
<Compile Include="Search\Filter\Modes\ConditionlessFilterJson.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.Collections.Generic;
4+
using FluentAssertions;
5+
6+
namespace Nest.Tests.Unit.Search.Aggregations
7+
{
8+
[TestFixture]
9+
public class SingleBucketAggregationTests
10+
{
11+
[Test]
12+
public void CanSetInnerAggregationsInConstructor()
13+
{
14+
var bucket = new SingleBucket(new Dictionary<string, IAggregation> {
15+
{"some_agg", new KeyItem { Key = "agg_key", DocCount = 123 }}
16+
});
17+
18+
bucket.Aggregations.Should().ContainKey("some_agg");
19+
20+
var item = (KeyItem) bucket.Aggregations["some_agg"];
21+
item.DocCount.Should().Be(123);
22+
item.Key.Should().Be("agg_key");
23+
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)