Cardinality Aggregation Usageedit

Fluent DSL exampleedit

s => s
.Aggregations(a => a
    .Cardinality("state_count", c => c
        .Field(p => p.State)
        .PrecisionThreshold(100)
    )
)

Object Initializer syntax exampleedit

new SearchRequest<Project>
{
    Aggregations = new CardinalityAggregation("state_count", Field<Project>(p => p.State))
    {
        PrecisionThreshold = 100
    }
}

Example json output.

{
  "aggs": {
    "state_count": {
      "cardinality": {
        "field": "state",
        "precision_threshold": 100
      }
    }
  }
}

Handling Responsesedit

response.ShouldBeValid();
var projectCount = response.Aggs.Cardinality("state_count");
projectCount.Should().NotBeNull();
projectCount.Value.Should().Be(3);