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.
Date Range aggregation
editDate Range aggregation
editA range aggregation that is dedicated for date values.
Fluent Syntax
editvar result = client.Search<ElasticsearchProject>(s => s .Aggregations(a => a .DateRange("my_date_range_agg", d => d .Field(p => p.StartedOn) .Format("MM-yyy") .Ranges( r => r.To("now-10M/M"), r => r.From("now-10M/M") ) ) ) ); var agg = result.Aggs.DateRange("my_date_range_agg");
Object Initializer Syntax
editvar request = new SearchRequest { Aggregations = new Dictionary<string, IAggregationContainer> { { "my_date_range_agg", new AggregationContainer { DateRange = new DateRangeAggregator { Field = "startedOn", Format = "MM-yyy", Ranges = new List<DateExpressionRange> { new DateExpressionRange().To("now-10M/M"), new DateExpressionRange().From("now-10M/M") } } } } } }; var result = client.Search<ElasticsearchProject>(request); var agg = result.Aggs.DateRange("my_date_range_agg");
Refer to the {ref_current}/search-aggregations-bucket-daterange-aggregation.html[original docs] for more information.