Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fluent API for composite aggregation sources #8227

Open
stijnherreman opened this issue Jun 10, 2024 · 0 comments
Open

Fluent API for composite aggregation sources #8227

stijnherreman opened this issue Jun 10, 2024 · 0 comments

Comments

@stijnherreman
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants