Histogram Aggregation Usageedit

Fluent DSL exampleedit

s => s
.Aggregations(a => a
    .Histogram("commits", h => h
        .Field(p => p.NumberOfCommits)
        .Interval(100)
        .Missing(0)
        .Order(HistogramOrder.KeyDescending)
        .Offset(1.1)
    )
)

Object Initializer syntax exampleedit

new SearchRequest<Project>
{
    Aggregations = new HistogramAggregation("commits")
    {
        Field = Field<Project>(p => p.NumberOfCommits),
        Interval = 100,
        Missing = 0,
        Order = HistogramOrder.KeyDescending,
        Offset = 1.1
    }
}

Example json output.

{
  "aggs": {
    "commits": {
      "histogram": {
        "field": "numberOfCommits",
        "interval": 100.0,
        "missing": 0.0,
        "order": {
          "_key": "desc"
        },
        "offset": 1.1
      }
    }
  }
}

Handling Responsesedit

response.ShouldBeValid();
var commits = response.Aggs.Histogram("commits");
commits.Should().NotBeNull();
commits.Buckets.Should().NotBeNull();
commits.Buckets.Count.Should().BeGreaterThan(0);
foreach (var item in commits.Buckets)
    item.DocCount.Should().BeGreaterThan(0);