首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >6 ElasticsearchTemplate和JPA中ElasticsearchRepository的选择

6 ElasticsearchTemplate和JPA中ElasticsearchRepository的选择

作者头像
天涯泪小武
发布2019-01-17 10:52:54
发布2019-01-17 10:52:54
2.1K0
举报
文章被收录于专栏:SpringCloud专栏SpringCloud专栏

通过前面的文章可以知道,JPA中有个ElasticsearchRepository可以做Elasticsearch的相关增删改查,用法和普通的CRUDRepository是一样的,这样就能统一ElasticSearch和普通的JPA操作,获得和操作mysql一样的代码体验。但是同时可以看到ElasticsearchRepository的功能是比较少的,简单查询够用,但复杂查询就不够了。

而ElasticsearchTemplate则提供了更多的方法来完成更多的功能,也包括分页之类的,他其实就是一个封装好的ElasticSearch Util功能类,通过直接连接client来完成数据的操作。

如https://stackoverflow.com/questions/28897404/spring-data-elasticsearchs-elasticsearchtemplate-vs-elasticsearchrepository上所说,ElasticsearchTemplate, by other hand, is an elasticsearch client for working with your indexes, and it's not typed or related to your domain classes. It's more powerful since you can do many tasks not available to the repository implementation, like deleting an index or making aggregated searchs.

那么我们在service里,可以灵活的使用这两个来操作ElasticSearch。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017年06月05日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档