Skip to content

Fluent API for composite aggregation sources #8227

Closed
@stijnherreman

Description

@stijnherreman

Is your feature request related to a problem? Please describe.
There doesn't seem to be a fluent API to define composite aggregation sources.

Describe the solution you'd like
I'd like an API similar to .MultiTerms(...).

var response = await client.SearchAsync<Foo>(search => search
    .Aggregations(aggregations => aggregations
        .Add("foo", aggregation => aggregation
            .MultiTerms(multiTerms => multiTerms
                .Terms(
                    terms => terms
                        .Field(foo => foo.Bar),
                    terms => terms
                        .Field(foo => foo.Baz)
                )
            )
        )
    )
    // ...

Describe alternatives you've considered
Currently using the non-fluent API. I was a bit confused initially by the method taking a ICollection<IDictionary<string, CompositeAggregationSource>> parameter.

var response = await client.SearchAsync<Foo>(search => search
    .Aggregations(aggregations => aggregations
        .Add("foo", aggregation => aggregation
            .Composite(composite => composite
                .Sources(new[]
                {
                    new Dictionary<string, CompositeAggregationSource>()
                    {
                        { "bar", new() { Terms = new() { Field = "bar" } } }
                    },
                    new Dictionary<string, CompositeAggregationSource>()
                    {
                        { "baz", new() { Terms = new() { Field = "baz" } } }
                    }
                })
            )
        )
    )
    // ...

Additional context
I'm using a composite aggregation because I need to stream all buckets.
The example at #7822 (comment) was quite helpful.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions