弹性搜索,spring-数据和休眠
elasticsearch, spring-data and hibernate
我正在尝试将弹性搜索添加到我的项目中。我使用 hibernate
作为 ORM
来访问我的数据。我想将我的一些实体索引到 elasticsearch
集群。
为此,我想到了使用我当前现有的休眠实体 class 并在休眠实体之外添加 spring-data-elasticsearch
注释。
我对这个选择不是完全有信心,我想知道它是否存在一些设计错误(注释之间可能存在冲突?)。
例如,我必须添加 2 个 Id 注释:"@javax.persistence.Id
" 用于 hibernate
,"@org.springframework.data.annotation.Id
" 用于弹性搜索。
提前感谢您的意见。
我成功地配置并测试了我使用相同 class 进行数据库存储和弹性搜索索引的想法。我意识到 ES 索引器包括 class 的每个字段,而不仅仅是 "elastic search annotated".
更重要的是,spring-data-elasticsearch 没有用。我认为这是因为 ES 索引器使用 JPA 注释,并且我的每个字段 class 已经有自己的休眠...
总而言之,我要为数据库存储做一个 class,为我的 ES 索引做另一个(信息较少)。
您可以同时使用 Spring Data JPA 和 SPring Data Elasticsearch。使用此配置:
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ElasticsearchCrudRepository.class))
@EnableElasticsearchRepositories(includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ElasticsearchCrudRepository.class))
public class DataConfiguration {
...
}
您可能还想考虑本机 Hibernate 与 Elasticsearch 的集成:
- http://in.relation.to/2016/05/24/ElasticsearchintegrationReachesBeta1/
我正在尝试将弹性搜索添加到我的项目中。我使用 hibernate
作为 ORM
来访问我的数据。我想将我的一些实体索引到 elasticsearch
集群。
为此,我想到了使用我当前现有的休眠实体 class 并在休眠实体之外添加 spring-data-elasticsearch
注释。
我对这个选择不是完全有信心,我想知道它是否存在一些设计错误(注释之间可能存在冲突?)。
例如,我必须添加 2 个 Id 注释:"@javax.persistence.Id
" 用于 hibernate
,"@org.springframework.data.annotation.Id
" 用于弹性搜索。
提前感谢您的意见。
我成功地配置并测试了我使用相同 class 进行数据库存储和弹性搜索索引的想法。我意识到 ES 索引器包括 class 的每个字段,而不仅仅是 "elastic search annotated".
更重要的是,spring-data-elasticsearch 没有用。我认为这是因为 ES 索引器使用 JPA 注释,并且我的每个字段 class 已经有自己的休眠...
总而言之,我要为数据库存储做一个 class,为我的 ES 索引做另一个(信息较少)。
您可以同时使用 Spring Data JPA 和 SPring Data Elasticsearch。使用此配置:
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ElasticsearchCrudRepository.class))
@EnableElasticsearchRepositories(includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ElasticsearchCrudRepository.class))
public class DataConfiguration {
...
}
您可能还想考虑本机 Hibernate 与 Elasticsearch 的集成: - http://in.relation.to/2016/05/24/ElasticsearchintegrationReachesBeta1/