Range aggregation

edit

A multi-bucket value source based aggregation that enables the user to define a set of ranges - each representing a bucket.

Fluent DSL

edit
var result = _client.Search<ElasticsearchProject>(s => s
    .Aggregations(a => a
        .Range("my_range_agg", ra => ra
            .Field(p => p.LOC)
            .Ranges(
                r => r.To(11000),
                r => r.From(11000).To(12000),
                r => r.From(12000)
            )
        )
    )
);

var rangeAgg = result.Aggs.Range("my_range_agg");

Object Initializer Syntax

edit
var request = new SearchRequest
{
    Aggregations = new Dictionary<string, IAggregationContainer>
    {
        { "my_range_agg", new AggregationContainer
            {
                Range = new RangeAggregator
                {
                    Field = "followers.age",
                    Ranges = new List<Range<double>>
                    {
                        new Range<double>().To(11000),
                        new Range<double>().From(11000).To(12000),
                        new Range<double>().From(12000)
                    }
                }
            }
        }
    }
};

var result = client.Search<ElasticsearchProject>(request);

var agg = result.Aggs.Range("my_range_agg");

Refer to the original docs for more information.