Upgrading from 4.1.x to 4.2.x

本节介绍从 4.1.x 版到 4.2.x 版的重大更改,以及如何使用新引入的功能替代已删除的功能。

This section describes breaking changes from version 4.1.x to 4.2.x and how removed features can be replaced by new introduced features.

Deprecations

@Document parameters

@Document 注释的相关于索引设置(useServerConfiguration, shards, replicas, refreshIntervallindexStoretype)的参数已移至 @Setting 注释。仍可在 @Document 中使用,但已被弃用。

The parameters of the @Document annotation that are relevant for the index settings (useServerConfiguration, shards. replicas, refreshIntervall and indexStoretype) have been moved to the @Setting annotation. Use in @Document is still possible but deprecated.

Removals

版本 4.0 中弃用了 @Score 注解(用于在实体中设置得分返回值),现已将其移除。得分值已返回在封装返回实体的 SearchHit 实例中。

The @Score annotation that was used to set the score return value in an entity was deprecated in version 4.0 and has been removed. Score values are returned in the SearchHit instances that encapsulate the returned entities.

已移除 org.springframework.data.elasticsearch.ElasticsearchException 类。剩余用法已替换为 org.springframework.data.mapping.MappingExceptionorg.springframework.dao.InvalidDataAccessApiUsageException

The org.springframework.data.elasticsearch.ElasticsearchException class has been removed. The remaining usages have been replaced with org.springframework.data.mapping.MappingException and org.springframework.dao.InvalidDataAccessApiUsageException.

已移除弃用的 ScoredPageScrolledPage@AggregatedPage 和其实现。

The deprecated ScoredPage, ScrolledPage @AggregatedPage and implementations has been removed.

已移除弃用的 GetQueryDeleteQuery

The deprecated GetQuery and DeleteQuery have been removed.

已移除 ReactiveSearchOperationsReactiveDocumentOperations 中的弃用 find 方法。

The deprecated find methods from ReactiveSearchOperations and ReactiveDocumentOperations have been removed.

Breaking Changes

RefreshPolicy

Enum package changed

在 4.1 版中,可以通过在自定义配置类中覆盖 AbstractReactiveElasticsearchConfiguration.refreshPolicy() 方法来配置 ReactiveElasticsearchTemplate 的刷新策略。此方法的返回值是 org.elasticsearch.action.support.WriteRequest.RefreshPolicy 类的实例。

It was possible in 4.1 to configure the refresh policy for the ReactiveElasticsearchTemplate by overriding the method AbstractReactiveElasticsearchConfiguration.refreshPolicy() in a custom configuration class. The return value of this method was an instance of the class org.elasticsearch.action.support.WriteRequest.RefreshPolicy.

现在,配置必须返回 org.springframework.data.elasticsearch.core.RefreshPolicy。此枚举具有相同的值,并触发与之前相同的行为,因此只需调整 import 语句。

Now the configuration must return org.springframework.data.elasticsearch.core.RefreshPolicy. This enum has the same values and triggers the same behaviour as before, so only the import statement has to be adjusted.

Refresh behaviour

如果写请求上的刷新策略不为 null,则 ElasticsearchOperationsReactiveElasticsearchOperations 现将显式使用模板中设置的 RefreshPolicy。如果刷新策略为 null,则不会执行任何特殊操作,因此会使用集群默认值。在此版本之前,ElasticsearchOperations 一直在使用集群默认值。

ElasticsearchOperations and ReactiveElasticsearchOperations now explicitly use the RefreshPolicy set on the template for write requests if not null. If the refresh policy is null, then nothing special is done, so the cluster defaults are used. ElasticsearchOperations was always using the cluster default before this version.

当刷新策略为 null 时,ElasticsearchRepositoryReactiveElasticsearchRepository 的提供实现将执行显式刷新。这与以前版本的中的行为相同。如果设置了刷新策略,则它也将被存储库使用。

The provided implementations for ElasticsearchRepository and ReactiveElasticsearchRepository will do an explicit refresh when the refresh policy is null. This is the same behaviour as in previous versions. If a refresh policy is set, then it will be used by the repositories as well.

Refresh configuration

在按照 Elasticsearch Clients中通过使用 ElasticsearchConfigurationSupportAbstractElasticsearchConfiguration`或 `AbstractReactiveElasticsearchConfiguration`的描述配置 Spring Data Elasticsearch 时,刷新策略将初始化为 `null。之前,响应式代码会将此初始化为 IMMEDIATE,现在,响应式代码和非响应式代码表现相同。

When configuring Spring Data Elasticsearch like described in Elasticsearch Clients by using ElasticsearchConfigurationSupport, AbstractElasticsearchConfiguration or AbstractReactiveElasticsearchConfiguration the refresh policy will be initialized to null. Previously the reactive code initialized this to IMMEDIATE, now reactive and non-reactive code show the same behaviour.

Method return types

delete methods that take a Query

reactive 方法以前返回包含已删除文档数的 Mono<Long>,而非 reactive 版本则为空。现在,它们返回包含有关已删除文档和可能发生的错误的更详细信息的 Mono<ByQueryResponse>

The reactive methods previously returned a Mono<Long> with the number of deleted documents, the non reactive versions were void. They now return a Mono<ByQueryResponse> which contains much more detailed information about the deleted documents and errors that might have occurred.

multiget methods

multiget 的实现以前仅在非 reactive 实现中返回 List<T> 中的找到的实体,在 reactive 实现中返回 Flux<T> 中的实体。如果请求包含未找到的 ID,则没有提供有关这些内容丢失的信息。用户需要将返回的 ID 与请求的 ID 进行比较,以找出缺少哪些内容。

The implementations of multiget previousl only returned the found entities in a List<T> for non-reactive implementations and in a Flux<T> for reactive implementations. If the request contained ids that were not found, the information that these are missing was not available. The user needed to compare the returned ids to the requested ones to find which ones were missing.

现在,multiget 方法为每个请求的 ID 返回 MultiGetItem。这包含有关失败(如不存在的索引)的信息,以及有关该项目是否存在(因此包含在 MultiGetItem 中)或不存在的信息。

Now the multiget methods return a MultiGetItem for every requested id. This contains information about failures (like non existing indices) and the information if the item existed (then it is contained in the `MultiGetItem) or not.