New

The executive guide to generative AI

Read more
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.

Global aggregation

edit

Defines a single bucket of all the documents within the search execution context. This context is defined by the indices and the document types you’re searching on, but is not influenced by the search query itself.

Fluent DSL

edit
var result = client.Search<ElasticsearchProject>(s => s
    .Query(q => q
        .Match(m => m
            .OnField(p => p.Country)
            .Query("Malaysia")))
    .Aggregations(a => a
        .Global("global_bucket", d => d
            .Aggregations(aa => aa
                .Terms("bool_count", t => t
                    .Field(f => f.BoolValue)
                )
            )
        )
    )
);

var agg = result.Aggs.Global("global_bucket");
var bools = agg.Terms("bool_count");

Object Initializer Syntax

edit
var request = new SearchRequest
{
    Query = new QueryContainer(new MatchQuery
    {
        Field = "country",
        Query = "Malaysia"
    }),
    Aggregations = new Dictionary<string, IAggregationContainer>
    {
        { "global_bucket", new AggregationContainer
            {
                Global = new GlobalAggregator(),
                Aggregations = new Dictionary<string, IAggregationContainer>
                {
                    { "bool_count", new AggregationContainer
                        {
                            Terms = new TermsAggregator
                            {
                                Field = "boolValue"
                            }
                        }
                    }
                }
            }
        }
    }
};

var result = client.Search<ElasticsearchProject>(request);

var agg = result.Aggs.Global("global_bucket");
var bools = agg.Terms("bool_count");

Refer to the {ref_current}/search-aggregations-bucket-global-aggregation.html[original docs] for more information.

Was this helpful?
Feedback