Average Aggregation Usageedit

Fluent DSL exampleedit

s => s
.Aggregations(a => a
    .Average("average_commits", avg => avg
        .Meta(m => m
            .Add("foo", "bar")
        )
        .Field(p => p.NumberOfCommits)
        .Missing(10)
        .Script(ss=>ss.Inline("_value * 1.2").Lang("groovy"))
    )
)

Object Initializer syntax exampleedit

new SearchRequest<Project>
{
    Aggregations = new AverageAggregation("average_commits", Field<Project>(p => p.NumberOfCommits))
    {
        Meta = new Dictionary<string, object>
        {
            { "foo", "bar" }
        },
        Missing = 10,
        Script = new InlineScript("_value * 1.2") { Lang = "groovy" }
    }
}

Example json output. 

{
  "aggs": {
    "average_commits": {
      "meta": {
        "foo": "bar"
      },
      "avg": {
        "field": "numberOfCommits",
        "missing": 10.0,
        "script": {
          "inline": "_value * 1.2",
          "lang": "groovy"
        }
      }
    }
  }
}

Handling Responsesedit

response.ShouldBeValid();
var commitsAvg = response.Aggs.Average("average_commits");
commitsAvg.Should().NotBeNull();
commitsAvg.Value.Should().BeGreaterThan(0);
commitsAvg.Meta.Should().NotBeNull().And.HaveCount(1);
commitsAvg.Meta["foo"].Should().Be("bar");