从 4.2.x 升级到 4.3.x
本节描述了从版本 4.2.x 到 4.3.x 的重大更改,以及如何用新引入的功能替换已删除的功能。
|
Elasticsearch 正在开发一个新的客户端来替换 Spring Data Elasticsearch 还从其 API 类和方法中移除或替换了 对于那些无法轻易替换的类,其使用被标记为已弃用,我们正在开发替代方案。 |
已弃用
suggest 方法
在 SearchOperations 中,以及在 ElasticsearchOperations 中,接受 org.elasticsearch.search.suggest.SuggestBuilder 作为参数并返回 org.elasticsearch.action.search.SearchResponse 的 suggest 方法已被弃用。请改用 SearchHits<T> search(Query query, Class<T> clazz),传入一个可以包含 SuggestBuilder 的 NativeSearchQuery,并从返回的 SearchHit<T> 中读取建议结果。
在 ReactiveSearchOperations 中,新的 suggest 方法现在返回一个 Mono<org.springframework.data.elasticsearch.core.suggest.response.Suggest>。同样,旧方法已被弃用。
重大更改
从 API 中移除 org.elasticsearch 类。
-
在
org.springframework.data.elasticsearch.annotations.CompletionContext注解中,属性type()已从org.elasticsearch.search.suggest.completion.context.ContextMapping.Type更改为org.springframework.data.elasticsearch.annotations.CompletionContext.ContextMappingType,可用的枚举值相同。 -
在
org.springframework.data.elasticsearch.annotations.Document注解中,versionType()属性已更改为org.springframework.data.elasticsearch.annotations.Document.VersionType,可用的枚举值相同。 -
在
org.springframework.data.elasticsearch.core.query.Query接口中,searchType()属性已更改为org.springframework.data.elasticsearch.core.query.Query.SearchType,可用的枚举值相同。 -
在
org.springframework.data.elasticsearch.core.query.Query接口中,timeout()的返回值已更改为java.time.Duration。 -
SearchHits<T>类不再包含org.elasticsearch.search.aggregations.Aggregations。相反,它现在包含org.springframework.data.elasticsearch.core.AggregationsContainer<T>类的一个实例,其中T是所使用的底层客户端的具体聚合类型。目前这将是一个org.springframework.data.elasticsearch.core.clients.elasticsearch7.ElasticsearchAggregations对象;之后将提供不同的实现。对ReactiveSearchOperations.aggregate()函数也进行了相同的更改,它们现在返回Flux<AggregationContainer<?>>。使用聚合的程序需要更改为将返回值转换为适当的类以进一步处理。 -
以前可能抛出
org.elasticsearch.ElasticsearchStatusException的方法现在将抛出org.springframework.data.elasticsearch.RestStatusException。
Query 的 field 和 sourceFilter 属性的处理
在 4.2 版本之前,Query 的 fields 属性被解释并添加到 sourceFilter 的包含列表中。这是不正确的,因为这些对于 Elasticsearch 来说是不同的东西。这已经得到纠正。因此,依赖于使用 fields 来指定应从文档的 _source 返回哪些字段的代码可能不再起作用,应改为使用 sourceFilter。
search_type 默认值
Elasticsearch 中 search_type 的默认值为 query_then_fetch。现在,这也已在 Query 实现中设置为默认值,它以前设置为 dfs_query_then_fetch。
BulkOptions 更改
org.springframework.data.elasticsearch.core.query.BulkOptions 类的一些属性更改了类型
-
timeout属性的类型已更改为java.time.Duration。 -
refreshPolicy属性的类型已更改为org.springframework.data.elasticsearch.core.RefreshPolicy。
IndicesOptions 更改
Spring Data Elasticsearch 现在使用 org.springframework.data.elasticsearch.core.query.IndicesOptions 而不是 org.elasticsearch.action.support.IndicesOptions。