Reputation: 155
Currently, I am mapping the elastic search hit to a POJO and then reiterating it to save in a list.
List<Content> contentList = new ArrayList<>();
final BoolQueryBuilder qb = QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery("tenantId","yes"));
SearchHits<Content> hits = elasticsearchTemplate.search(new NativeSearchQuery(qb), Content.class,IndexCoordinates.of("preview"));
contentList = hits.stream().map(SearchHit::getContent).collect(Collectors.toList());
Is there a way i can directly map the elastic result to List of Content POJO with out iterating it from Search Hit.
Upvotes: 0
Views: 473
Reputation: 19471
You can use the following:
contentList = (List<Content>) SearchHitSupport.unwrapSearchHits(hits);
Upvotes: 2