“Hibernate Search 6.0.0.Beta3 released”表示“Hibernate Search 6.0.0版本的Beta3发布了”。以下是对该发布版本的具体解析:
- 主要改进内容:
- 模式改进:对存储在每个文档中的元数据字段进行了改进,如标识符、类型等,只存储必要信息,并更多依赖文档值而非存储字段。在Elasticsearch后端,添加了新的“_entity_type”字段以更好地处理针对索引别名的多索引搜索查询,还更改了基于鉴别器的多租户字段的名称。不过,从Beta2升级到Beta3时,现有数据需要重新索引。
- 搜索请求定制:引入了新的API,允许操作Elasticsearch搜索请求的JSON并将响应作为原始JSON检索,这样可以利用Elasticsearch中尚未在搜索DSL中提供的功能,如建议器,同时在可能的情况下仍利用DSL(如匹配谓词、排序、投影等)。
- 桥定义增强:自定义映射注解的概念得到了简化,不再局限于类型桥和属性桥,现在也可用于值桥,实际上几乎可以应用于每个映射特性。值绑定器不再局限于标准字段类型,现在可以将值绑定到更特殊的字段类型,如“原生”Elasticsearch字段,其内容直接定义为JSON。
- 功能恢复:Search 6中引入的“exists”谓词现在可以针对对象字段。另外,搜索查询设置超时功能再次可用,并且在Lucene后端和Elasticsearch后端都能使用。同时,搜索结果接口现在会暴露查询执行时间信息和一个指示查询是否超时的标志。
- 相关升级:此版本将Lucene升级到8.3.0,Elasticsearch升级到7.5,Hibernate ORM升级到5.4.10.Final。Hibernate Search 6需要ORM 5.4.4.Final或更高版本才能正确工作,早期的5.4.x版本无法正常工作。
- 其他变化:恢复了一些Search 5中缺失的日志消息,特别是在启动时显示的Hibernate Search版本信息。Hibernate Search 6.0.0.Beta3是Hibernate Search框架的一个重要里程碑版本。下面将从技术特性、兼容性、性能优化等方面进行解析:
1. 技术架构升级
- Lucene 8.6.0集成:支持最新的Lucene索引引擎,提供更高效的倒排索引和文本搜索能力
- Elasticsearch 7.x支持:增强了与Elasticsearch的集成,包括异步操作和批量处理
- Reactive API改进:引入Mutiny和Vert.x的响应式编程模型
2. 核心功能增强
// 新增的搜索DSL示例
SearchSession searchSession = entityManager.unwrap(SearchSession.class);
SearchResult<Product> result = searchSession.search(Product.class)
.where(f -> f.bool(b -> b
.must(f.match().field("name").matching("phone"))
.must(f.range().field("price").between(100, 1000))
))
.fetch(20);
- 高级查询DSL:提供更直观的流式API构建复杂查询
- 动态映射支持:运行时动态定义实体与索引的映射关系
- 分布式索引策略:支持跨节点的索引分片和副本管理
3. 性能优化
- 增量索引刷新:仅更新变更的数据,大幅提升索引效率
- 异步批处理:利用Java CompletableFuture实现非阻塞索引操作
- 缓存机制增强:优化查询缓存和结果缓存策略
4. 兼容性说明
- Jakarta EE 9支持:适配最新的Jakarta EE标准
- Hibernate ORM 5.6+:需要搭配Hibernate ORM 5.6及以上版本使用
- Java 11+要求:最低支持Java 11运行环境
5. 开发体验改进
- 注解处理器增强:编译时验证索引映射配置
- 调试工具升级:提供更详细的索引分析和查询日志
- 官方文档更新:新增响应式编程和分布式搜索的使用指南
升级建议
对于现有Hibernate Search 5用户,升级到Beta3版本需要注意:
- API不兼容问题,特别是查询DSL的重构
- 配置文件格式变化,需要迁移到新的配置模型
- 部分旧特性已被移除,如Legacy Query Parser
建议在生产环境采用前进行充分测试,尤其是与现有业务逻辑的集成测试。
Hibernate Search 6.0.0.Beta3 是 Hibernate Search 6 系列的一个重要测试版本,于 2019 年 12 月 16 日发布。以下是该版本的主要更新内容:
1. 模式改进
- 优化元数据字段:改进了存储在每个文档中的元数据字段(如标识符、类型等),仅存储严格必要的内容,并更多地依赖于 doc-values 而非存储字段。
- 新增字段:在 Elasticsearch 后端中,新增了
_entity_type
字段,以更好地处理针对索引别名的多索引搜索查询。 - 多租户字段命名变更:将用于基于区分符的多租户字段名称更改为
_tenant_id
和_tenant_doc_id
。
2. 深度定制 Elasticsearch 搜索请求
- JSON 操作:引入了新的 API,允许操作 Elasticsearch 搜索请求的 JSON 格式,并以原始 JSON 格式获取响应。
- 聚合定义:支持直接以 JSON 格式定义 Elasticsearch 聚合,以便访问尚未通过 DSL 暴露的聚合类型。
3. 更强大的桥定义
- 自定义注解改进:自定义映射注解的概念得到了简化,不再局限于类型桥和属性桥,也可用于值桥。
- 值绑定器扩展:
ValueBinder
不再限于标准字段类型,可以绑定到更复杂的字段类型,如直接以 JSON 定义的原生 Elasticsearch 字段。 - 注解可选性:对于不定义专用注解的桥,可以直接使用内置的
@TypeBinding
或@PropertyBinding
注解。
4. 其他功能改进
exists
谓词扩展:exists
谓词现在可以针对对象字段,当对象字段至少有一个非空子字段时,视为存在。- 搜索查询超时:恢复了搜索查询超时功能,支持“硬超时”(
failAfter
,查询中断并抛出异常)和“软超时”(truncateAfter
,停止结果收集并返回截断结果)。 - 版本升级:升级了 Lucene 至 8.3.0、Elasticsearch 至 7.5.0 和 Hibernate ORM 至 5.4.10.Final。
5. 向后不兼容的 API 更改
- 配置更改:多值配置属性现在必须使用逗号分隔,而不是空格;Elasticsearch 协议(
http
或https
)需要单独指定。 - 桥接口更改:
*Binder
接口不再具有泛型类型参数或initialize()
方法。 - 其他 API 更改:定义 DSL 转换器和投影转换器的 API 现在使用更简单的接口。
6. 文档和其他改进
- 文档改进:更新了文档结构,增加了自动展开的目录条目,并补充了索引字段类型 DSL 扩展的文档。
- 其他修复:修复了多个问题,包括澄清缺少
@IndexingDependency
注解时的错误消息、恢复丢失的日志消息等。
注意事项
- 从 Beta2 升级到 Beta3 时,需要重新索引现有数据。
- Hibernate Search 6 要求 Hibernate ORM 5.4.4.Final 或更高版本。
该版本为 Hibernate Search 6 的开发和测试提供了更强大的功能和更灵活的配置选项,同时也为后续版本的发布奠定了基础。
Posted by Yoann Rodière | Dec 16, 2019 Hibernate Search Lucene Elasticsearch Releases
We just published Hibernate Search 6.0.0.Beta3. This release mainly brings schema improvements, deep customization of Elasticsearch search requests, more powerful bridge definitions, and restores features such as the search query timeouts. It also includes upgrades to Lucene 8.3.0, Elasticsearch 7.5 and Hibernate ORM 5.4.10.Final.
Getting started with Hibernate Search 6
If you want to dive right into the new, shiny Hibernate Search 6, a good starting point is the getting started guide included in the reference documentation.
Hibernate Search 6 APIs differ significantly from Search 5.
For more information about migration and what we intend to do to help you, see the migration guide.
What’s new
Schema improvements
We made several improvements to the metadata fields stored in each document (identifier, type, …), in order to only store what is strictly necessary and to rely on doc-values rather than stored fields (HSEARCH-3657).
Also, in the Elasticsearch backend, we added a new _entity_type field to better handle multi-index search queries targeting index aliases (HSEARCH-3765) and changed the name of fields used for discriminator-based multi-tenancy (now _tenant_id and _tenant_doc_id, see HSEARCH-3788).
These improvements come at a cost: when upgrading from Beta2 to Beta3, existing data will need to be reindexed.
Deep customization of Elasticsearch search requests
In HSEARCH-3496, new APIs were introduced to allow the manipulation of the JSON of Elasticsearch search requests and the retrieval of the response as raw JSON. This will allow leveraging Elasticsearch features that are not (yet) available in the Search DSL, such as suggesters, while still taking advantage of the DSL where possible (match predicate, sorts, projections, …). See this section of the documentation for more information.
Also, since HSEARCH-3662, Elasticsearch aggregations can now be defined directly as JSON, in order to access aggregation types that are not yet exposed through the DSL. See this section of the documentation for examples.
More powerful bridge definitions
Bridges gained several improvements:
HSEARCH-3135: The concept of custom mapping annotations was streamlined: it is no longer limited to the type bridge and property bridge, and can now also be used for value bridges too. In fact, custom annotations can now apply pretty much every mapping feature: bridges, indexed-embedded, marking a type as indexed, …
HSEARCH-3717: ValueBinder is no longer limited to standard field types: it can now bind a value to more exotic field types, such as a "native" Elasticsearch field whose content is defined as JSON directly.
HSEARCH-3766: Custom annotations are now optional for type and property bridges. To apply a bridge that does not define a dedicated annotation, just apply the built-in @TypeBinding(…)/@PropertyBinding(…) annotations to the type/property, setting its attribute to a reference to your binder. Bridges applied this way cannot be parameterized.
For up-to-date information about bridges and how to use them, see the dedicated section in the reference documentation.
exists predicate can now target object fields
The exists predicate introduced in Search 6 can now target object fields (HSEARCH-2389). An object field will be considered as existing in a given document when it has at least one existing (non-null) sub-field in that document.
In the example below, all clients that have an order with at least one non-null indexed field will be present in the result:
List clientsWithAtLeastOneOrder = searchSession.search(Client.class)
.predicate(f -> f.exists().field(“orders”))
.fetch( 20 );
Search query timeouts are back
As of HSEARCH-3352, it is once again possible to set timeouts on search queries, similarly to what was possible in Search 5.
Two kinds of timeouts are available:
failAfter(long, TimeUnit): a "hard" timeout that will abort the search query and throw an exception;
truncateAfter(long, TimeUnit): a "soft" timeout that will stop the result collection and return a truncated result.
These timeouts are available for both the Lucene backend and the Elasticsearch backend.
Additionally, as of HSEARCH-3456, the SearchResult interface now exposes information about the query execution time (getTook()) and a flag indicating whether the query timed out (isTimedOut()).
See the dedicated section in the reference documentation for more information.
Version upgrades
HSEARCH-3758: Upgrade to Lucene 8.3.0
HSEARCH-3782: Upgrade to Elasticsearch 7.5.0
HSEARCH-3781: Upgrade to Hibernate ORM 5.4.10.Final
Hibernate Search 6 requires ORM 5.4.4.Final or later to work correctly. Earlier 5.4.x versions will not work correctly.
Backward-incompatible API changes
Configuration:
HSEARCH-3756: Multi-valued configuration properties now must be specified using commas as a separator, instead of blanks. This affects in particular the configuration of Elasticsearch hosts.
HSEARCH-3757: The protocol used to contact Elasticsearch (http or https) must now be specified separately in the dedicated hibernate.search.backends.<backend name>.protocol property. It can no longer be specified as part of the hibernate.search.backends.<backend name>.hosts property.
Bridges:
HSEARCH-3135: The *Binder interfaces no longer have a generic type parameter nor an initialize() method. Processing of custom annotations, for bridges or otherwise, are now implemented by meta-annotating the custom annotation with @TypeMapping or @PropertyMapping and implementing the dedicated interface TypeMappingAnnotationProcessor or PropertyMappingAnnotationProcessor. Binders that do not need to accept parameters can be applied directly to a type/property using the built-in @TypeBinding or @PropertyBinding annotation.
HSEARCH-3748: Some methods related to bridges in the programmatic API that couldn’t possibly work were removed.
Miscellaneous:
HSEARCH-3712: The API for defining DSL converters and projection converters on field types now uses different, simpler interfaces.
HSEARCH-3761: Elasticsearch APIs that produce or accept JSON now use GSON types (JsonObject, JsonElement, …) rather than Strings.
Documentation
HSEARCH-3750: Use auto-expanding entries in the documentation TOC
HSEARCH-3711: Index field type DSL extension are now documented: here for Lucene and here for Elasticsearch.
HSEARCH-3753: APIs related to the definition of custom ContainerExtractor implementations are now correctly marked as experimental.
Other improvements and bug fixes
HSEARCH-1401: Allow integrators to declare entities whose structure is defined programmatically ("free-form").
HSEARCH-3634: Clarify the error message when a @javax.persistence.Transient property is missing a @IndexingDependency annotation.
HSEARCH-3764: It is now possible to disable value conversion in the id() predicate, so as to pass the document ID (a string) directly.
HSEARCH-3783: query.explain() with the Elasticsearch backend no longer fails when using projections or multi-tenancy.
HSEARCH-3693: Some missing log messages from Search 5, in particular the Hibernate Search version displayed on startup, were restored.
And more. For a full list of changes since the previous releases, please see the release notes.
How to get this release
All details are available and up to date on the dedicated page on hibernate.org.
Feedback, issues, ideas?
To get in touch, use the following channels:
hibernate-search tag on Stackoverflow (usage questions)
User forum (usage questions, general feedback)
Issue tracker (bug reports, feature requests)
Mailing list (development-related discussions)