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 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 filterAgg = response.Aggs.Filter("bethels_projects"); filterAgg.Should().NotBeNull(); filterAgg.DocCount.Should().BeGreaterThan(0); var tags = filterAgg.Terms("project_tags"); tags.Should().NotBeNull(); tags.Buckets.Should().NotBeEmpty();
Empty Filter
editWhen the collection of filters is empty or all are conditionless, NEST will serialize them to an empty object.
Fluent DSL example
edits => s .Aggregations(aggs => aggs .Filter("empty_filter", date => date .Filter(f => f .Bool(b => b .Filter(new QueryContainer[0]) ) ) ) )
Object Initializer syntax example
editnew SearchRequest<Project> { Aggregations = new FilterAggregation("empty_filter") { Filter = new BoolQuery { Filter = new List<QueryContainer>() } } }
Example json output.
{ "aggs": { "empty_filter": { "filter": {} } } }
Handling Responses
editresponse.ShouldBeValid(); response.Aggs.Filter("empty_filter").DocCount.Should().BeGreaterThan(0);
Inline Script Filter
editFluent DSL example
edits => s .Aggregations(aggs => aggs .Filter(_aggName, date => date .Filter(f => f .Script(b => b .Inline(_ctxNumberofCommits) ) ) ) )
Object Initializer syntax example
editnew SearchRequest<Project> { Aggregations = new FilterAggregation(_aggName) { Filter = new ScriptQuery { Inline = _ctxNumberofCommits } } }
Example json output.
{ "aggs": { "script_filter": { "filter": { "script": { "script": { "inline": "_source.numberOfCommits > 0" } } } } } }
Handling Responses
editresponse.ShouldBeValid(); response.Aggs.Filter(_aggName).DocCount.Should().BeGreaterThan(0);