WARNING: Version 5.x has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Range Aggregation Usageedit
Fluent DSL exampleedit
s => s .Aggregations(a => a .Range("commit_ranges", ra => ra .Field(p => p.NumberOfCommits) .Ranges( r => r.To(100), r => r.From(100).To(500), r => r.From(500) ) ) )
Object Initializer syntax exampleedit
new SearchRequest<Project> { Aggregations = new RangeAggregation("commit_ranges") { Field = Field<Project>(p => p.NumberOfCommits), Ranges = new List<AggregationRange> { { new AggregationRange { To = 100 } }, { new AggregationRange { From = 100, To = 500 } }, { new AggregationRange { From = 500 } } } } }
Example json output.
{ "aggs": { "commit_ranges": { "range": { "field": "numberOfCommits", "ranges": [ { "to": 100.0 }, { "from": 100.0, "to": 500.0 }, { "from": 500.0 } ] } } } }
Handling Responsesedit
response.ShouldBeValid(); var commitRanges = response.Aggs.Range("commit_ranges"); commitRanges.Should().NotBeNull(); commitRanges.Buckets.Count.Should().Be(3); commitRanges.Buckets.FirstOrDefault(r => r.Key == "*-100.0").Should().NotBeNull(); commitRanges.Buckets.FirstOrDefault(r => r.Key == "100.0-500.0").Should().NotBeNull(); commitRanges.Buckets.FirstOrDefault(r => r.Key == "500.0-*").Should().NotBeNull();