Skip to content

Commit 3350b07

Browse files
jonyadamitMpdreamz
authored andcommitted
Added missing pipeline aggregations
Original commit by @jonyadamit, squashed, reformatted, introduced sigma on extendedstatsbucket by @Mpdreamz
1 parent 746e2c8 commit 3350b07

File tree

10 files changed

+3058
-2614
lines changed

10 files changed

+3058
-2614
lines changed

src/Nest/Aggregations/AggregationContainer.cs

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,17 @@ public interface IAggregationContainer
154154
IMinBucketAggregation MinBucket { get; set; }
155155

156156
[JsonProperty("sum_bucket")]
157-
ISumBucketAggregation SumBucket { get; set; }
158-
157+
ISumBucketAggregation SumBucket { get; set; }
158+
159+
[JsonProperty("stats_bucket")]
160+
IStatsBucketAggregation StatsBucket { get; set; }
161+
162+
[JsonProperty("extended_stats_bucket")]
163+
IExtendedStatsBucketAggregation ExtendedStatsBucket { get; set; }
164+
165+
[JsonProperty("percentiles_bucket")]
166+
IPercentilesBucketAggregation PercentilesBucket { get; set; }
167+
159168
[JsonProperty("moving_avg")]
160169
IMovingAverageAggregation MovingAverage { get; set; }
161170

@@ -242,8 +251,14 @@ public class AggregationContainer : IAggregationContainer
242251

243252
public IMinBucketAggregation MinBucket { get; set; }
244253

245-
public ISumBucketAggregation SumBucket { get; set; }
246-
254+
public ISumBucketAggregation SumBucket { get; set; }
255+
256+
public IStatsBucketAggregation StatsBucket { get; set; }
257+
258+
public IExtendedStatsBucketAggregation ExtendedStatsBucket { get; set; }
259+
260+
public IPercentilesBucketAggregation PercentilesBucket { get; set; }
261+
247262
public IMovingAverageAggregation MovingAverage { get; set; }
248263

249264
public ICumulativeSumAggregation CumulativeSum { get; set; }
@@ -349,8 +364,14 @@ public class AggregationContainerDescriptor<T> : DescriptorBase<AggregationConta
349364

350365
IMinBucketAggregation IAggregationContainer.MinBucket { get; set; }
351366

352-
ISumBucketAggregation IAggregationContainer.SumBucket { get; set; }
353-
367+
ISumBucketAggregation IAggregationContainer.SumBucket { get; set; }
368+
369+
IStatsBucketAggregation IAggregationContainer.StatsBucket { get; set; }
370+
371+
IExtendedStatsBucketAggregation IAggregationContainer.ExtendedStatsBucket { get; set; }
372+
373+
IPercentilesBucketAggregation IAggregationContainer.PercentilesBucket { get; set; }
374+
354375
IMovingAverageAggregation IAggregationContainer.MovingAverage { get; set; }
355376

356377
ICumulativeSumAggregation IAggregationContainer.CumulativeSum { get; set; }
@@ -497,8 +518,20 @@ public AggregationContainerDescriptor<T> MinBucket(string name,
497518

498519
public AggregationContainerDescriptor<T> SumBucket(string name,
499520
Func<SumBucketAggregationDescriptor, ISumBucketAggregation> selector) =>
500-
_SetInnerAggregation(name, selector, (a, d) => a.SumBucket = d);
501-
521+
_SetInnerAggregation(name, selector, (a, d) => a.SumBucket = d);
522+
523+
public AggregationContainerDescriptor<T> StatsBucket(string name,
524+
Func<StatsBucketAggregationDescriptor, IStatsBucketAggregation> selector) =>
525+
_SetInnerAggregation(name, selector, (a, d) => a.StatsBucket = d);
526+
527+
public AggregationContainerDescriptor<T> ExtendedStatsBucket(string name,
528+
Func<ExtendedStatsBucketAggregationDescriptor, IExtendedStatsBucketAggregation> selector) =>
529+
_SetInnerAggregation(name, selector, (a, d) => a.ExtendedStatsBucket = d);
530+
531+
public AggregationContainerDescriptor<T> PercentilesBucket(string name,
532+
Func<PercentilesBucketAggregationDescriptor, IPercentilesBucketAggregation> selector) =>
533+
_SetInnerAggregation(name, selector, (a, d) => a.PercentilesBucket = d);
534+
502535
public AggregationContainerDescriptor<T> MovingAverage(string name,
503536
Func<MovingAverageAggregationDescriptor, IMovingAverageAggregation> selector) =>
504537
_SetInnerAggregation(name, selector, (a, d) => a.MovingAverage = d);
@@ -521,8 +554,8 @@ public AggregationContainerDescriptor<T> BucketSelector(string name,
521554

522555
public AggregationContainerDescriptor<T> Sampler(string name,
523556
Func<SamplerAggregationDescriptor<T>, ISamplerAggregation> selector) =>
524-
_SetInnerAggregation(name, selector, (a, d) => a.Sampler = d);
525-
557+
_SetInnerAggregation(name, selector, (a, d) => a.Sampler = d);
558+
526559
/// <summary>
527560
/// Fluent methods do not assign to properties on `this` directly but on IAggregationContainers inside `this.Aggregations[string, IContainer]
528561
/// </summary>
@@ -534,27 +567,27 @@ Func<TAggregator, TAggregatorInterface> selector
534567
where TAggregator : IAggregation, TAggregatorInterface, new()
535568
where TAggregatorInterface : IAggregation
536569
{
537-
var aggregator = selector(new TAggregator());
538-
539-
//create new isolated container for new aggregator and assign to the right property
570+
var aggregator = selector(new TAggregator());
571+
572+
//create new isolated container for new aggregator and assign to the right property
540573
var container = new AggregationContainer() { Meta = aggregator.Meta };
541574

542-
assignToProperty(container, aggregator);
543-
544-
//create aggregations dictionary on `this` if it does not exist already
575+
assignToProperty(container, aggregator);
576+
577+
//create aggregations dictionary on `this` if it does not exist already
545578
IAggregationContainer self = this;
546-
if (self.Aggregations == null) self.Aggregations = new Dictionary<string, IAggregationContainer>();
547-
548-
//if the aggregator is a bucket aggregator (meaning it contains nested aggregations);
579+
if (self.Aggregations == null) self.Aggregations = new Dictionary<string, IAggregationContainer>();
580+
581+
//if the aggregator is a bucket aggregator (meaning it contains nested aggregations);
549582
var bucket = aggregator as IBucketAggregation;
550583
if (bucket != null && bucket.Aggregations.HasAny())
551-
{
552-
//make sure we copy those aggregations to the isolated container's
553-
//own .Aggregations container (the one that gets serialized to "aggs")
584+
{
585+
//make sure we copy those aggregations to the isolated container's
586+
//own .Aggregations container (the one that gets serialized to "aggs")
554587
IAggregationContainer d = container;
555588
d.Aggregations = bucket.Aggregations;
556-
}
557-
//assign the aggregations container under Aggregations ("aggs" in the json)
589+
}
590+
//assign the aggregations container under Aggregations ("aggs" in the json)
558591
self.Aggregations[key] = container;
559592
return this;
560593
}
@@ -565,4 +598,4 @@ public void Accept(IAggregationVisitor visitor)
565598
new AggregationWalker().Walk(this, visitor);
566599
}
567600
}
568-
}
601+
}

src/Nest/Aggregations/AggregationsHelper.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,20 @@ public ScriptedMetricAggregate ScriptedMetric(string key)
5151
: this.TryGet<ScriptedMetricAggregate>(key);
5252
}
5353

54-
public StatsAggregate Stats(string key) => this.TryGet<StatsAggregate>(key);
55-
56-
public ExtendedStatsAggregate ExtendedStats(string key) => this.TryGet<ExtendedStatsAggregate>(key);
57-
54+
public StatsAggregate Stats(string key) => this.TryGet<StatsAggregate>(key);
55+
56+
public StatsAggregate StatsBucket(string key) => this.TryGet<StatsAggregate>(key);
57+
58+
public ExtendedStatsAggregate ExtendedStats(string key) => this.TryGet<ExtendedStatsAggregate>(key);
59+
60+
public ExtendedStatsAggregate ExtendedStatsBucket(string key) => this.TryGet<ExtendedStatsAggregate>(key);
61+
5862
public GeoBoundsAggregate GeoBounds(string key) => this.TryGet<GeoBoundsAggregate>(key);
5963

60-
public PercentilesAggregate Percentiles(string key) => this.TryGet<PercentilesAggregate>(key);
61-
64+
public PercentilesAggregate Percentiles(string key) => this.TryGet<PercentilesAggregate>(key);
65+
66+
public PercentilesAggregate PercentilesBucket(string key) => this.TryGet<PercentilesAggregate>(key);
67+
6268
public PercentilesAggregate PercentileRanks(string key) => this.TryGet<PercentilesAggregate>(key);
6369

6470
public TopHitsAggregate TopHits(string key) => this.TryGet<TopHitsAggregate>(key);
@@ -70,8 +76,8 @@ public FiltersAggregate Filters(string key)
7076
return named;
7177

7278
var anonymous = this.TryGet<BucketAggregate>(key);
73-
return anonymous != null
74-
? new FiltersAggregate { Buckets = anonymous.Items.OfType<FiltersBucketItem>().ToList(), Meta = anonymous.Meta }
79+
return anonymous != null
80+
? new FiltersAggregate { Buckets = anonymous.Items.OfType<FiltersBucketItem>().ToList(), Meta = anonymous.Meta }
7581
: null;
7682
}
7783

@@ -171,4 +177,4 @@ private MultiBucketAggregate<TBucket> GetBucket<TBucket>(string key)
171177
};
172178
}
173179
}
174-
}
180+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Nest
5+
{
6+
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
7+
[ContractJsonConverter(typeof(AggregationJsonConverter<ExtendedStatsBucketAggregation>))]
8+
public interface IExtendedStatsBucketAggregation : IPipelineAggregation
9+
{
10+
[JsonProperty("sigma")]
11+
int? Sigma { get; set; }
12+
}
13+
14+
public class ExtendedStatsBucketAggregation
15+
: PipelineAggregationBase, IExtendedStatsBucketAggregation
16+
{
17+
internal ExtendedStatsBucketAggregation() { }
18+
19+
public ExtendedStatsBucketAggregation(string name, SingleBucketsPath bucketsPath)
20+
: base(name, bucketsPath)
21+
{ }
22+
23+
public int? Sigma { get; set; }
24+
25+
internal override void WrapInContainer(AggregationContainer c) => c.ExtendedStatsBucket = this;
26+
}
27+
28+
public class ExtendedStatsBucketAggregationDescriptor
29+
: PipelineAggregationDescriptorBase<ExtendedStatsBucketAggregationDescriptor, IExtendedStatsBucketAggregation, SingleBucketsPath>
30+
, IExtendedStatsBucketAggregation
31+
{
32+
33+
int? IExtendedStatsBucketAggregation.Sigma { get; set; }
34+
35+
public ExtendedStatsBucketAggregationDescriptor Sigma(int? sigma) => Assign(a => a.Sigma = sigma);
36+
37+
}
38+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
namespace Nest
7+
{
8+
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
9+
[ContractJsonConverter(typeof(AggregationJsonConverter<PercentilesBucketAggregation>))]
10+
public interface IPercentilesBucketAggregation : IPipelineAggregation
11+
{
12+
[JsonProperty("percents")]
13+
IEnumerable<double> Percents { get; set; }
14+
}
15+
16+
public class PercentilesBucketAggregation
17+
: PipelineAggregationBase, IPercentilesBucketAggregation
18+
{
19+
public IEnumerable<double> Percents { get; set; }
20+
21+
internal PercentilesBucketAggregation() { }
22+
23+
public PercentilesBucketAggregation(string name, SingleBucketsPath bucketsPath)
24+
: base(name, bucketsPath)
25+
{ }
26+
27+
internal override void WrapInContainer(AggregationContainer c) => c.PercentilesBucket = this;
28+
}
29+
30+
public class PercentilesBucketAggregationDescriptor
31+
: PipelineAggregationDescriptorBase<PercentilesBucketAggregationDescriptor, IPercentilesBucketAggregation, SingleBucketsPath>
32+
, IPercentilesBucketAggregation
33+
{
34+
IEnumerable<double> IPercentilesBucketAggregation.Percents { get; set; }
35+
36+
public PercentilesBucketAggregationDescriptor Percents(IEnumerable<double> percentages) =>
37+
Assign(a => a.Percents = percentages?.ToList());
38+
39+
public PercentilesBucketAggregationDescriptor Percents(params double[] percentages) =>
40+
Assign(a => a.Percents = percentages?.ToList());
41+
42+
}
43+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Nest
4+
{
5+
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
6+
[ContractJsonConverter(typeof(AggregationJsonConverter<StatsBucketAggregation>))]
7+
public interface IStatsBucketAggregation : IPipelineAggregation { }
8+
9+
public class StatsBucketAggregation
10+
: PipelineAggregationBase, IStatsBucketAggregation
11+
{
12+
internal StatsBucketAggregation() { }
13+
14+
public StatsBucketAggregation(string name, SingleBucketsPath bucketsPath)
15+
: base(name, bucketsPath)
16+
{ }
17+
18+
internal override void WrapInContainer(AggregationContainer c) => c.StatsBucket = this;
19+
}
20+
21+
public class StatsBucketAggregationDescriptor
22+
: PipelineAggregationDescriptorBase<StatsBucketAggregationDescriptor, IStatsBucketAggregation, SingleBucketsPath>
23+
, IStatsBucketAggregation
24+
{
25+
}
26+
}

0 commit comments

Comments
 (0)