Average Aggregation Usage

edit

Fluent DSL example

edit
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 example

edit
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 Responses

edit
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");