Using the elasticsearchClient.search(query, 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?
Unfortunately, we don't support automatic type conversion for Aggregation the same way as we do for Search, because it's not possible to know what the end result of an Aggregation will be, since it depends on the type of Aggregation used and how they are chained/nested.
However, we do provide an easy way to convert from JsonData to compatible java classes:
public static class MyType{}
@Test
public void typedAggregate() {
TopHitsAggregate agg = null;
for (Hit<JsonData> hit: agg.hits().hits()) {
MyType data = hit.source().to(MyType.class);
// Do something with data
}
}
Sorry for the wait! Hope this can still be helpful.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.