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.
Handling responses
editHandling responses
editUsing the .Aggs
aggregation helper on ISearchResponse<T>
, we can fetch our aggregation results easily
in the correct type. Be sure to read more about .Aggs vs .Aggregations
Handling Responses
editresponse.ShouldBeValid(); var dateHistogram = response.Aggs.DateHistogram("projects_started_per_month"); dateHistogram.Should().NotBeNull(); dateHistogram.Buckets.Should().NotBeNull(); dateHistogram.Buckets.Count.Should().BeGreaterThan(10); foreach (var item in dateHistogram.Buckets) { item.Date.Should().NotBe(default(DateTime)); item.DocCount.Should().BeGreaterThan(0); var nested = item.Nested("project_tags"); nested.Should().NotBeNull(); var nestedTerms = nested.Terms("tags"); nestedTerms.Buckets.Count.Should().BeGreaterThan(0); }