Skip to content

Commit 4cc715c

Browse files
committed
Internalize intermediate bucket object, more sensible base classes
1 parent 6a425ad commit 4cc715c

File tree

10 files changed

+41
-34
lines changed

10 files changed

+41
-34
lines changed

src/Nest/Aggregations/AggregationResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ namespace Nest
88
[ExactContractJsonConverter(typeof(AggregationResultJsonConverter))]
99
public interface IAggregationResult
1010
{
11-
Dictionary<string, object> Meta { get; set; }
11+
IDictionary<string, object> Meta { get; set; }
1212
}
1313
}

src/Nest/Aggregations/AggregationResultJsonConverter.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,17 @@ private IAggregationResult GetSingleBucketAggregation(JsonReader reader, JsonSer
181181
{
182182
reader.Read();
183183
var docCount = (reader.Value as long?).GetValueOrDefault(0);
184-
var bucket = new SingleBucket() { DocCount = docCount };
184+
var bucket = new SingleBucket { DocCount = docCount };
185185
reader.Read();
186186
if (reader.TokenType == JsonToken.PropertyName
187187
&& ((string)reader.Value) == "buckets"
188188
)
189189
{
190190
var b = this.GetBucketAggregation(reader, serializer) as Bucket;
191-
return new DocCountBucket()
191+
return new Bucket
192192
{
193193
DocCount = docCount,
194194
Items = b.Items
195-
196195
};
197196
}
198197

src/Nest/Aggregations/AggregationsHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public FiltersBucket Filters(string key)
8989

9090
public DocCountBucket<SignificantTermItem> SignificantTerms(string key)
9191
{
92-
var bucket = this.TryGet<DocCountBucket>(key);
92+
var bucket = this.TryGet<Bucket>(key);
9393
return bucket == null
9494
? null
9595
: new DocCountBucket<SignificantTermItem>

src/Nest/Aggregations/Bucket/Bucket.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33

44
namespace Nest
55
{
6+
public interface IBucketItem { }
7+
68
public interface IBucket : IAggregationResult
79
{
810
IDictionary<string, IAggregationResult> Aggregations { get; }
911
}
1012

11-
public interface IBucketItem { }
12-
13-
public class Bucket : IAggregationResult
13+
public abstract class BucketBase : AggregationsHelper, IBucket
1414
{
15-
public IEnumerable<IAggregationResult> Items { get; set; }
16-
public long? DocCountErrorUpperBound { get; set; }
17-
public long? SumOtherDocCount { get; set; }
18-
public Dictionary<string, object> Meta { get; set; }
15+
protected BucketBase() { }
16+
protected BucketBase(IDictionary<string, IAggregationResult> aggregations) : base(aggregations) { }
17+
18+
public IDictionary<string, object> Meta { get; set; }
1919
}
2020

2121
public class Bucket<TBucketItem> : BucketBase
@@ -27,11 +27,13 @@ public Bucket(IDictionary<string, IAggregationResult> aggregations) : base(aggre
2727
public IList<TBucketItem> Items { get; set; }
2828
}
2929

30-
public abstract class BucketBase : AggregationsHelper, IBucket
30+
// Intermediate object used for deserialization
31+
internal class Bucket : IAggregationResult
3132
{
32-
protected BucketBase() { }
33-
protected BucketBase(IDictionary<string, IAggregationResult> aggregations) : base(aggregations) { }
34-
35-
public Dictionary<string, object> Meta { get; set; }
33+
public IEnumerable<IAggregationResult> Items { get; set; }
34+
public long? DocCountErrorUpperBound { get; set; }
35+
public long? SumOtherDocCount { get; set; }
36+
public IDictionary<string, object> Meta { get; set; }
37+
public long DocCount { get; set; }
3638
}
3739
}

src/Nest/Aggregations/Bucket/DocCountBucket.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,12 @@ public interface IDocCountBucket : IBucket
77
long DocCount { get; }
88
}
99

10-
public class DocCountBucket<TBucketItem> : BucketBase, IDocCountBucket
10+
public class DocCountBucket<TBucketItem> : Bucket<TBucketItem>, IDocCountBucket
1111
where TBucketItem : IBucketItem
1212
{
1313
public DocCountBucket() { }
1414
public DocCountBucket(IDictionary<string, IAggregationResult> aggregations) : base(aggregations) { }
1515

16-
public IList<TBucketItem> Items { get; set; }
17-
1816
public long DocCount { get; internal set; }
1917
}
20-
21-
public class DocCountBucket : BucketBase, IAggregationResult
22-
{
23-
public long DocCount { get; set; }
24-
public IEnumerable<IAggregationResult> Items { get; set; }
25-
26-
}
2718
}

src/Nest/Aggregations/Bucket/KeyedBucket.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
namespace Nest
44
{
5-
public class KeyedBucket : BucketBase, IBucketItem
5+
public class KeyedBucket : SingleBucket, IBucketItem
66
{
77
public KeyedBucket() { }
88
public KeyedBucket(IDictionary<string, IAggregationResult> aggregations) : base(aggregations) { }
99

1010
public string Key { get; set; }
1111
public string KeyAsString { get; set; }
12-
public long DocCount { get; set; }
1312
}
1413
}

src/Nest/Aggregations/Bucket/SingleBucket.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33

44
namespace Nest
55
{
6-
public class SingleBucket : BucketBase
6+
public class Bucket : BucketBase
77
{
8-
public SingleBucket() { }
8+
public Bucket() { }
99

10-
public SingleBucket(IDictionary<string, IAggregationResult> aggregations) : base(aggregations) { }
10+
public Bucket(IDictionary<string, IAggregationResult> aggregations) : base(aggregations) { }
1111

12-
[JsonProperty("doc_count")]
1312
public long DocCount { get; set; }
1413
}
1514
}

src/Nest/Aggregations/Metric/Metric.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ public interface IMetric : IAggregationResult
99

1010
public abstract class MetricBase : IMetric
1111
{
12-
public Dictionary<string, object> Meta { get; set; }
12+
public IDictionary<string, object> Meta { get; set; }
1313
}
1414
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Nest
8+
{
9+
public class SingleBucket : BucketBase
10+
{
11+
public SingleBucket() { }
12+
13+
public SingleBucket(IDictionary<string, IAggregationResult> aggregations) : base(aggregations) { }
14+
15+
public long DocCount { get; set; }
16+
}
17+
}
133 KB
Binary file not shown.

0 commit comments

Comments
 (0)