You are looking at documentation for an older release.
Not what you want? See the
current release documentation.
Terms Aggregation Usageedit
Fluent DSL Exampleedit
s => s .Aggregations(a => a .Terms("states", st => st .Field(p => p.State) .MinimumDocumentCount(2) .Size(5) .ShardSize(100) .ShowTermDocumentCountError() .ExecutionHint(TermsAggregationExecutionHint.Map) .Missing("n/a") .Script("'State of Being: '+_value") .Order(TermsOrder.TermAscending) .Order(TermsOrder.CountDescending) .Meta(m => m .Add("foo", "bar") ) ) )
Object Initializer Syntax Exampleedit
new SearchRequest<Project> { Aggregations = new TermsAggregation("states") { Field = Field<Project>(p => p.State), MinimumDocumentCount = 2, Size = 5, ShardSize = 100, ShowTermDocumentCountError = true, ExecutionHint = TermsAggregationExecutionHint.Map, Missing = "n/a", Script = new InlineScript("'State of Being: '+_value"), Order = new List<TermsOrder> { TermsOrder.TermAscending, TermsOrder.CountDescending }, Meta = new Dictionary<string, object> { { "foo", "bar" } } } }
Example json output.
{ "aggs": { "states": { "meta": { "foo": "bar" }, "terms": { "field": "state", "min_doc_count": 2, "size": 5, "shard_size": 100, "show_term_doc_error_count": true, "execution_hint": "map", "missing": "n/a", "script": { "inline": "'State of Being: '+_value" }, "order": [ { "_term": "asc" }, { "_count": "desc" } ] } } } }
Handling Responsesedit
response.IsValid.Should().BeTrue(); var states = response.Aggs.Terms("states"); states.Should().NotBeNull(); states.DocCountErrorUpperBound.Should().HaveValue(); states.SumOtherDocCount.Should().HaveValue(); foreach (var item in states.Buckets) { item.Key.Should().NotBeNullOrEmpty(); item.DocCount.Should().BeGreaterOrEqualTo(1); } states.Meta.Should().NotBeNull().And.HaveCount(1); states.Meta["foo"].Should().Be("bar");