从 4.1.x 升级到 4.2.x
本节描述了从版本 4.1.x 到 4.2.x 的破坏性变更,以及如何使用新引入的功能替代已被移除的功能。
移除
用于在实体中设置评分返回值的 @Score 注解已在 4.0 版本中被弃用并移除。
评分值将在封装返回实体的 SearchHit 实例中返回。
org.springframework.data.elasticsearch.ElasticsearchException 类已被移除。
剩余的用法已替换为 org.springframework.data.mapping.MappingException 和 org.springframework.dao.InvalidDataAccessApiUsageException。
已弃用的 ScoredPage、ScrolledPage、@AggregatedPage 及其实现已被移除。
已弃用的 GetQuery 和 DeleteQuery 已被移除。
来自 ReactiveSearchOperations 和 ReactiveDocumentOperations 的已弃用 find 方法已被移除。
重大变更
刷新策略
枚举包已更改
在 4.1 版本中,可以通过在自定义配置类中重写方法 AbstractReactiveElasticsearchConfiguration.refreshPolicy() 来为 ReactiveElasticsearchTemplate 配置刷新策略。
该方法的返回值是 org.elasticsearch.action.support.WriteRequest.RefreshPolicy 类的一个实例。
现在配置必须返回 org.springframework.data.elasticsearch.core.RefreshPolicy。
此枚举具有与之前相同的值并触发相同的行为,因此只需调整 import 语句。
刷新行为
ElasticsearchOperations 和 ReactiveElasticsearchOperations 现在如果非空,将显式使用模板上为写请求设置的 RefreshPolicy。
如果刷新策略为 null,则不执行任何特殊操作,因此将使用集群默认值。在此版本之前,ElasticsearchOperations 始终使用集群默认值。
ElasticsearchRepository 和 ReactiveElasticsearchRepository 提供的实现在刷新策略为 null 时会执行显式刷新。
这与之前版本的行为相同。
如果设置了刷新策略,则存储库也将使用该策略。
刷新配置
当按照 Elasticsearch 客户端 中所述,使用 ElasticsearchConfigurationSupport、AbstractElasticsearchConfiguration 或 AbstractReactiveElasticsearchConfiguration 配置 Spring Data Elasticsearch 时,刷新策略将初始化为 null。
此前,响应式代码将其初始化为 IMMEDIATE,现在响应式和非响应式代码表现出相同的行为。