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 Usage
editRange Aggregation Usage
editFluent DSL example
edits => 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 example
editnew SearchRequest<Project> { Aggregations = new RangeAggregation("commit_ranges") { Field = Field<Project>(p => p.NumberOfCommits), Ranges = new List<Nest.Range> { { new Nest.Range { To = 100 } }, { new Nest.Range { From = 100, To = 500 } }, { new Nest.Range { 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 Responses
editresponse.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();