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

Top hits aggregation - support multitype type hits #2408

Closed
llRandom opened this issue Nov 22, 2016 · 3 comments
Closed

Top hits aggregation - support multitype type hits #2408

llRandom opened this issue Nov 22, 2016 · 3 comments

Comments

@llRandom
Copy link

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);
    });
@Mpdreamz
Copy link
Member

We have a special ILazyDocument type that you can use to defer the deserialization of your document type.

Then you can call .As<MyObject>() on these to materialize them.

@llRandom
Copy link
Author

Thank you, that might work as a workaround instead of Newtonsoft.Json.Linq.JObject type but this interface doesn't allow to specify cast type at runtime (I can't pass required deserialization type as an argument). Besides, it looks odd to me that approaches for root hits and hits from top aggregation are so different.

russcam added a commit that referenced this issue Jun 28, 2017
russcam added a commit that referenced this issue Jun 29, 2017
russcam added a commit that referenced this issue Jun 29, 2017
* Use serializer when deserializing LazyDocument to T

When converting a LazyDocument to type T, use the JsonNetSerializer configured, along with all registered contract resolvers.

Fixes #2788

* Direct cast

* Add non-generic overload for As()

Relates #2408
russcam added a commit that referenced this issue Jun 29, 2017
* Use serializer when deserializing LazyDocument to T

When converting a LazyDocument to type T, use the JsonNetSerializer configured, along with all registered contract resolvers.

Fixes #2788

* Direct cast

* Add non-generic overload for As()

Relates #2408

(cherry picked from commit 109bcb0)
russcam added a commit that referenced this issue Jun 29, 2017
* Use serializer when deserializing LazyDocument to T

When converting a LazyDocument to type T, use the JsonNetSerializer configured, along with all registered contract resolvers.

Fixes #2788

* Direct cast

* Add non-generic overload for As()

Relates #2408

(cherry picked from commit 109bcb0)
awelburn pushed a commit to Artesian/elasticsearch-net that referenced this issue Nov 6, 2017
* Use serializer when deserializing LazyDocument to T

When converting a LazyDocument to type T, use the JsonNetSerializer configured, along with all registered contract resolvers.

Fixes elastic#2788

* Direct cast

* Add non-generic overload for As()

Relates elastic#2408

(cherry picked from commit 109bcb0)
@Mpdreamz
Copy link
Member

@llRandom while I agree this would be a super handy feature, in NEST 5.x it would be incredibly hard to introduce without backwards compatible breaking changes. Closing this as Elasticsearch 6.x no longer supports multiple types this should be ideally handled by the serializer itself.

In NEST 6.x and up it will be possible to configure a serializer just for _source's and field values so the responsibility will shift.

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

No branches or pull requests

2 participants