简体   繁体   中英

Elastic Search Result in List of POJO

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.

您可以使用以下内容:

contentList = (List<Content>) SearchHitSupport.unwrapSearchHits(hits);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM