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.
Average Aggregation Usage
editAverage Aggregation Usage
editFluent DSL example
edits => s .Aggregations(a => a .Average("average_commits", avg => avg .Meta(m => m .Add("foo", "bar") ) .Field(p => p.NumberOfCommits) .Missing(10) .Script("_value * 1.2") ) )
Object Initializer syntax example
editnew 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") } }
Example json output.
{ "aggs": { "average_commits": { "meta": { "foo": "bar" }, "avg": { "field": "numberOfCommits", "missing": 10.0, "script": { "inline": "_value * 1.2" } } } } }
Handling Responses
editresponse.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");