POJO列表中的弹性搜索结果

发布于 2025-01-30 23:54:43 字数 539 浏览 4 评论 0原文

目前,我将弹性搜索命中率映射到POJO,然后重申其保存在列表中。

 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());

有什么方法可以将弹性结果直接映射到content pojo列表中,并从搜索hit中迭代它。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惟欲睡 2025-02-06 23:54:43

您可以使用以下内容:

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

You can use the following:

contentList = (List<Content>) SearchHitSupport.unwrapSearchHits(hits);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文