Skip to content

Commit c509515

Browse files
committed
Simplify aggregation base classes and add meta to response
1 parent 6eeb889 commit c509515

File tree

17 files changed

+73
-53
lines changed

17 files changed

+73
-53
lines changed

src/Nest/Aggregations/AggregationContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ Func<TAggregator, TAggregatorInterface> selector
527527
where TAggregatorInterface : IAggregation
528528
{
529529
var aggregator = selector(new TAggregator());
530-
530+
531531
//create new isolated container for new aggregator and assign to the right property
532532
var container = new AggregationContainer();
533533
assignToProperty(container, aggregator);

src/Nest/Aggregations/AggregationResult.cs

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

src/Nest/Aggregations/AggregationResultJsonConverter.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,19 +376,18 @@ private IAggregationResult GetBucketAggregation(JsonReader reader, JsonSerialize
376376
if (reader.TokenType == JsonToken.StartObject)
377377
{
378378
reader.Read();
379-
var temp = new Dictionary<string, IAggregationResult>();
379+
var aggs = new Dictionary<string, IAggregationResult>();
380380
do
381381
{
382382
var name = reader.Value.ToString();
383383
reader.Read();
384384
var innerAgg = this.ReadAggregation(reader, serializer);
385-
temp.Add(name, innerAgg);
385+
aggs.Add(name, innerAgg);
386386
reader.Read();
387387
} while (reader.TokenType != JsonToken.EndObject);
388388

389-
var agg = new AggregationsHelper(temp);
390389
reader.Read();
391-
return new FiltersBucket(agg);
390+
return new FiltersBucket(aggs);
392391
}
393392

394393
if (reader.TokenType != JsonToken.StartArray)

src/Nest/Aggregations/Bucket/Bucket.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23

34
namespace Nest
@@ -7,15 +8,14 @@ public interface IBucket : IAggregationResult
78
IDictionary<string, IAggregationResult> Aggregations { get; }
89
}
910

10-
public interface IBucketItem : IAggregationResult
11-
{
12-
}
11+
public interface IBucketItem { }
1312

1413
public class Bucket : IAggregationResult
1514
{
1615
public IEnumerable<IAggregationResult> Items { get; set; }
1716
public long? DocCountErrorUpperBound { get; set; }
1817
public long? SumOtherDocCount { get; set; }
18+
public Dictionary<string, object> Meta { get; set; }
1919
}
2020

2121
public class Bucket<TBucketItem> : BucketBase
@@ -31,5 +31,7 @@ public abstract class BucketBase : AggregationsHelper, IBucket
3131
{
3232
protected BucketBase() { }
3333
protected BucketBase(IDictionary<string, IAggregationResult> aggregations) : base(aggregations) { }
34+
35+
public Dictionary<string, object> Meta { get; set; }
3436
}
3537
}

src/Nest/Aggregations/Bucket/DocCountBucket.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ public DocCountBucket(IDictionary<string, IAggregationResult> aggregations) : ba
1818
public long DocCount { get; internal set; }
1919
}
2020

21-
public class DocCountBucket : IAggregationResult
21+
public class DocCountBucket : BucketBase, IAggregationResult
2222
{
2323
public long DocCount { get; set; }
2424
public IEnumerable<IAggregationResult> Items { get; set; }
25+
2526
}
2627
}

src/Nest/Aggregations/Bucket/Filters/FiltersBucket.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,19 @@
44

55
namespace Nest
66
{
7-
public class FiltersBucket : IAggregationResult
7+
public class FiltersBucket : BucketBase, IAggregationResult
88
{
99
public FiltersBucket(IEnumerable<IAggregationResult> items)
1010
{
1111
Items = items;
1212
}
1313

14-
public FiltersBucket(AggregationsHelper helper)
15-
{
16-
Aggregations = helper;
17-
}
14+
public FiltersBucket(IDictionary<string, IAggregationResult> aggregations) : base(aggregations) { }
1815

19-
public SingleBucket NamedBucket(string key) => this.Aggregations?.Global(key);
16+
public SingleBucket NamedBucket(string key) => this.Global(key);
2017

2118
public IList<SingleBucket> AnonymousBuckets() => this.Items?.OfType<SingleBucket>().ToList();
2219

23-
public AggregationsHelper Aggregations { get; set; }
24-
2520
public IEnumerable<IAggregationResult> Items { get; set; }
2621
}
2722
}

src/Nest/Aggregations/Metric/ExtendedStats/ExtendedStatsMetric.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Nest
22
{
3-
public class ExtendedStatsMetric : IMetric
3+
public class ExtendedStatsMetric : MetricBase
44
{
55
public long Count { get; set; }
66
public double? Min { get; set; }

src/Nest/Aggregations/Metric/GeoBounds/GeoBoundsMetric.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Nest
22
{
3-
public class GeoBoundsMetric : IMetric
3+
public class GeoBoundsMetric : MetricBase
44
{
55
public GeoBoundsMetric()
66
{
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
namespace Nest
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Nest
25
{
36
public interface IMetric : IAggregationResult
47
{
58
}
9+
10+
public abstract class MetricBase : IMetric
11+
{
12+
public Dictionary<string, object> Meta { get; internal set; }
13+
}
614
}

src/Nest/Aggregations/Metric/Percentiles/PercentilesMetric.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class PercentileItem
99
public double Value { get; internal set; }
1010
}
1111

12-
public class PercentilesMetric : IMetric
12+
public class PercentilesMetric : MetricBase
1313
{
1414
public IList<PercentileItem> Items { get; internal set; } = new List<PercentileItem>();
1515
}

0 commit comments

Comments
 (0)