TopHits aggregation | How to get strong type from Java API?

I am extracting the hits from a TopHits aggregation using the Java API:

Map<String, Aggregate> aggregations = searchResponse.aggregations();
TopHitsAggregate topHitsAggregate = searchResponse.aggregations().get("topHits").topHits();
List<Hit<JsonData>> hits = topHitsAggregate.hits().hits();

Using the, MyType.class) call gives the search hits converted to the target type (MyType in this case) which is really convenient. What is the recommended way to get the TopHits documents converted to the target type instead of the raw JsonData?


Very good question. @swallez do we support it with the current version of the client?

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.