Skip to content

Top hits aggregation - support multitype type hits #2408

Closed
@llRandom

Description

@llRandom

Describe the feature:
Current version doesn't allow to get deserialized documents from TopHitsAggregate aggregation object if they have different types. An attempt to use an object as a generic type leads to an exception. The only workaround I've found is to use Newtonsoft.Json.Linq.JObject type for getting hits and then cast hits using ToObject(targetType) method:

var doss = topHitsAgg.Hits<Newtonsoft.Json.Linq.JObject>()
    .Select(hit =>
    {
        var type = GetType(hit.Type);
        return hit.Source.ToObject(type);
    });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions