Upgrading from 4.2.x to 4.3.x
本节介绍 4.2.x 到 4.3.x 版本的重大变动,以及如何使用新引入的功能替换移除的功能。
|
Elasticsearch 正在使用新的客户端来替换 |
Deprecations
suggest methods
在 SearchOperations 中,以及 ElasticsearchOperations 中,将 org.elasticsearch.search.suggest.SuggestBuilder 作为参数并返回 org.elasticsearch.action.search.SearchResponse 的 suggest 方法已被弃用。请改用 SearchHits<T> search(Query query, Class<T> clazz),传入一个 NativeSearchQuery,它可以包含一个 SuggestBuilder 并从返回的 SearchHit<T> 中读取建议结果。
在 ReactiveSearchOperations 中,新的 suggest 方法现在返回一个 Mono<org.springframework.data.elasticsearch.core.suggest.response.Suggest>。这里旧方法也被弃用。
Breaking Changes
Removal of org.elasticsearch classes from the API.
-
在
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>`class does not contain the `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。
Handling of field and sourceFilter properties of Query
在 4.2 版中,Query 的 fields 属性已被解释并添加到 sourceFilter 的包含列表中。这是不正确的,因为对于 Elasticsearch 来说,这两个是不同的东西。此问题现已更正。因此,依赖使用 fields 来指定应从文档的 _source' and should be changed to use the `sourceFilter 中返回哪些字段的代码可能不再运行。
search_type default value
Elasticsearch 中 search_type 的默认值是 query_then_fetch。这也已作为 Query 实现的默认值进行设置,此前设置为 dfs_query_then_fetch。
BulkOptions changes
org.springframework.data.elasticsearch.core.query.BulkOptions 类的某些属性已更改其类型:
-
timeout属性的类型已更改为java.time.Duration。 -
refreshPolicy属性的类型已更改为org.springframework.data.elasticsearch.core.RefreshPolicy。
IndicesOptions change
Spring Data Elasticsearch 现在使用 org.springframework.data.elasticsearch.core.query.IndicesOptions 而不是 org.elasticsearch.action.support.IndicesOptions。