从 4.2.x 升级到 4.3.x
本节描述了从版本 4.2.x 到 4.3.x 的破坏性变更,以及如何使用新引入的功能替代已被移除的功能。
|
Elasticsearch 正在开发一个新的客户端,它将取代 Spring Data Elasticsearch 还从其 API 类和方法中移除或替换了来自 无法轻松替换的类使用位置,此用法已标记为弃用,我们正在开发替代方案。 |
弃用
建议方法
在 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>。
此处旧方法也被标记为弃用。
重大变更
移除org.elasticsearch来自 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。
处理查询的 field 和 sourceFilter 属性
在 4.2 版本之前,fields 的 Query 属性会被解析并添加到 sourceFilter 的包含列表中。
这是不正确的,因为对于 Elasticsearch 而言,这些是不同的概念。
此问题已得到修正。
因此,依赖使用 fields 来指定应从文档的 _source' and should be changed to use the `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。