Handling Responsesedit

The AggregateDictionary found on `.Aggregations on ISearchResponse<T> has several helper methods so we can fetch our aggregation results easily in the correct type. Be sure to read more about these helper methods

Handling Responsesedit

response.ShouldBeValid();

var filterAgg = response.Aggregations.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 Filteredit

When the collection of filters is empty or all are conditionless, NEST will serialize them to an empty object.

a => a
.Filter("empty_filter", date => date
    .Filter(f => f
        .Bool(b => b
            .Filter(new QueryContainer[0])
        )
    )
)
new FilterAggregation("empty_filter")
{
    Filter = new BoolQuery
    {
        Filter = new List<QueryContainer>()
    }
}

Example json output. 

{
  "empty_filter": {
    "filter": {}
  }
}

response.ShouldNotBeValid();
a => a
.Filter(_aggName, date => date
    .Filter(f => f
        .Script(b => b
            .Source(_ctxNumberofCommits)
        )
    )
)
new FilterAggregation(_aggName)
{
    Filter = new ScriptQuery
    {
        Source = _ctxNumberofCommits
    }
}

Example json output. 

{
  "script_filter": {
    "filter": {
      "script": {
        "script": {
          "source": "_source.numberOfCommits > 0"
        }
      }
    }
  }
}

response.ShouldBeValid();
response.Aggregations.Filter(_aggName).DocCount.Should().BeGreaterThan(0);