Skip to content

Sub-Aggregate Not Deserializing #8359

Closed
@deinman

Description

@deinman

Elastic.Clients.Elasticsearch version:
8.15.6

Elasticsearch version:
8.13.0

.NET runtime version:
8.0.8

Operating system version:
Win 11

Description of the problem including expected versus actual behavior:
Passing a sub aggregate causes the resultant aggregate hits to not deserialize.

Steps to reproduce:

var terms = Aggregation.Terms(new TermsAggregation
{
    Field = Infer.Field<Model>(x => x.GroupId),
});

terms.Aggregations = new Dictionary<string, Aggregation>
{
    {
        "earliest_event", Aggregation.TopHits(new TopHitsAggregation
        {
            Sort = new List<SortOptions>
            {
                SortOptions.Field(Infer.Field<Model>(x => x.StartTime),
                    new FieldSort { Order = SortOrder.Asc })
            },
            Size = 1
        })
    }
};

var aggregations = new Dictionary<string, Aggregation> { { "events", terms } };

var request = new SearchRequest<Model>
{
    Aggregations = aggregations,
    Query = Query.MatchAll(new MatchAllQuery())
};

var result = await client.SearchAsync<Model>(request);
public class Model
{
    public Guid Id { get; set; }
    public DateTimeOffset StartTime { get; set; }
    public Guid? RecurrenceId { get; set; }
    public Guid GroupId => RecurrenceId ?? Id;
}

Image

Expected behavior
I'd expect the resultant Hits inside the TopHitsAggregate to be typed as Model. If there's somewhere else I need to define the TDocument other than the SearchRequest - I can't find it.

I've confirmed the data in the nested Hits has the expected information, it's just coming back as an object.

As a work-around, I'm able to just deserialize it in some code after it comes back, which is workable, but it seems like there should be a way to get that TDocument to apply so users don't have to manually deserialize the result.

Provide ConnectionSettings (if relevant):
N/A

Provide DebugInformation (if relevant):
N/A

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