“Hibernate Search 6.0.0.Beta1 released”表示“Hibernate Search 6.0.0版本的Beta1发布了”。以下是对该发布的具体解析:
- Hibernate Search简介:Hibernate Search是一个将Hibernate ORM与Apache Lucene或Elasticsearch集成的库,能自动为实体建立索引,提供全文搜索、地理空间搜索、聚合等高级搜索功能。
- Beta1版本的意义:
- API稳定性提升:该版本修正了API中剩余的一些不一致性问题,这意味着API在后续版本中大概率会保持稳定,开发人员基于此进行的开发工作更具可持续性,不必担心因API的大幅变动而频繁修改代码。
- 文档完善:完成了主要功能的文档编写,参考文档涵盖了所有常见用例和大多数高级用例。这为开发人员提供了全面的参考资料,有助于快速上手和深入了解框架的各种功能及使用方法。
- 新特性引入:引入了聚合功能,类似于Search 5的分面功能,丰富了Hibernate Search的功能特性,为开发人员在数据统计和分析方面提供了更强大的工具。
- 后续计划:虽然发布了Beta1版本,但在最终发布正式版之前,仍有大量工作要做,所以目前它还不是候选发布版本。开发团队会继续对其进行完善和优化,包括修复可能存在的bug、进一步优化性能、处理用户反馈等,以确保最终正式版的高质量和稳定性。
- 使用建议:对于开发人员来说,如果对Hibernate Search 6的新特性感兴趣,或者有相关项目需求,可以尝试使用该版本进行开发和测试。但由于它还是beta版本,可能存在一些未被发现的问题,在生产环境中使用时需谨慎评估风险。Hibernate Search 6.0.0.Beta1 是 Hibernate Search 框架从 5.x 版本重构后的首个重要测试版本,标志着向 Jakarta EE 9+ 生态的全面迁移。以下是对该版本的详细解析:
核心变化
-
Jakarta EE 9 兼容
全面采用jakarta.persistence
命名空间,不再支持旧的javax.persistence
。这意味着需要使用 Jakarta EE 9+ 兼容的应用服务器(如 WildFly 26+)。 -
Elasticsearch 集成增强
- 支持 Elasticsearch 7.x 和 8.x,包括新的 REST 客户端 API
- 提供更细粒度的索引管理(如分片配置、自定义映射)
- 优化批量操作性能(通过异步处理和背压机制)
-
API 重构
- 引入流畅的 DSL 构建查询,替代旧的
QueryBuilder
- 统一搜索接口,简化 Elasticsearch 和 Lucene 后端的切换
- 改进类型安全,减少运行时错误
- 引入流畅的 DSL 构建查询,替代旧的
-
索引生命周期管理
- 支持自动索引模式(创建、验证、更新)
- 提供索引健康检查和统计信息 API
- 增强的增量索引机制,减少数据库负载
代码示例对比
旧版 Hibernate Search 5.x
FullTextSession fullTextSession = Search.getFullTextSession(session);
QueryBuilder qb = fullTextSession.getSearchFactory()
.buildQueryBuilder()
.forEntity(Product.class)
.get();
org.apache.lucene.search.Query luceneQuery = qb
.keyword()
.onField("name")
.matching("phone")
.createQuery();
FullTextQuery jpaQuery = fullTextSession.createFullTextQuery(luceneQuery, Product.class);
List<Product> results = jpaQuery.getResultList();
新版 Hibernate Search 6.x
SearchSession searchSession = Search.session(entityManager);
SearchResult<Product> result = searchSession.search(Product.class)
.where(f -> f.match()
.field("name")
.matching("phone"))
.fetch(20);
List<Product> hits = result.hits();
迁移注意事项
-
依赖更新
需要替换所有javax.persistence
为jakarta.persistence
,并更新相关模块:<!-- 旧版 --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-search-orm</artifactId> <version>5.11.7.Final</version> </dependency> <!-- 新版 --> <dependency> <groupId>org.hibernate.search</groupId> <artifactId>hibernate-search-mapper-orm</artifactId> <version>6.0.0.Beta1</version> </dependency>
-
配置调整
- 使用
hibernate.search.backend
前缀替代旧的hibernate.search.default
- Elasticsearch 配置方式变更(如
type_mapping.enabled
改为schema_management.strategy
)
- 使用
-
API 兼容性
- 旧的
@FieldBridge
和@ClassBridge
被@ValueBridge
和@EntityBridge
取代 - 索引同步策略配置方式发生变化
- 旧的
已知限制
作为 Beta 版本,6.0.0.Beta1 仍存在以下不足:
- 某些高级 Lucene 特性尚未完全迁移
- 与部分 Hibernate ORM 5.x 特性的兼容性有待完善
- 官方文档和社区资源仍在更新中
建议在生产环境使用前进行充分测试,并关注后续 GA 版本的发布。
以下是关于 Hibernate Search 6.0.0.Beta1 的详细解析:
版本意义
Hibernate Search 6.0.0.Beta1 是 Hibernate Search 6 系列的一个重要里程碑版本,它标志着该版本已进入 Beta 阶段,整体稳定性更高,主要的 API 已经趋于稳定,最常用的 API 不再会改变,实现也经过了充分测试,且参考文档已涵盖所有常见用例和大多数高级用例。
新特性
- 聚合功能:引入了聚合功能,类似于 Hibernate Search 5 中的分面功能,但解决了 Search 5 中分面功能的一些长期问题,如聚合 API 使用更清晰一致的命名,支持对更多类型字段进行聚合,包括 Java 8 的日期/时间类型字段等。
- 与 Hibernate Envers 兼容:现在 Hibernate Search 6 在启用 Hibernate Envers 时能够正确启动并索引版本化实体的最新版本。
- 其他改进:修复了单值排序在嵌套字段内字段上的问题;重新支持在大规模索引时设置自定义监视器;
java.util.Date
属性持有java.sql.Date
值时能够正确索引;支持字符串类型的实体标识符等。
API 变化
- 包结构调整:多个包的名称发生了变化,例如
org.hibernate.search.engine.search.dsl.projection
被移动到org.hibernate.search.engine.search.projection.dsl
。 - 方法重命名:在程序化映射 API 中,
withExtractor()
被重命名为extractor()
,withExtractors()
被重命名为extractors()
,withoutExtractors()
被重命名为noExtractors()
;在谓词 DSL 中,onField()
等方法被标记为过时,推荐使用无前缀的版本;在排序 DSL 中,byField()
等以by
开头的方法也被标记为过时。 - 配置属性调整:一些配置属性被重命名以提高一致性,如
hibernate.search.backends.myBackend.analysis_configurer
改为hibernate.search.backends.myBackend.analysis.configurer
。
文档与兼容性
- 文档完善:所有主要功能的文档已经完成,包括全文搜索、映射和分析等核心概念,以及如何将 Hibernate ORM 实体映射到索引、自定义桥接器、查询 DSL 和 MassIndexer 的相关内容。
- 兼容性:Hibernate Search 6 需要 Hibernate ORM 5.4.4.Final 或更高版本才能正常工作。
未来工作
尽管 Hibernate Search 6.0.0.Beta1 已经取得了很大进展,但仍有一些工作需要在最终发布前完成,例如一些不太常用的特性(如滚动或错误处理器)尚未实现,一些比 Search 5 更好的改进(如搜索分析器或零停机大规模索引)也尚未实现,性能虽令人满意但仍需更彻底的测试,且后续可能还会更改索引格式,这将需要重新索引。
Posted by Yoann Rodière | Sep 24, 2019 Hibernate Search Lucene Elasticsearch Releases
Hibernate Search 6 just reached Beta status with the release of version 6.0.0.Beta1. This release clears the last remaining major hurdles: it fixes the few remaining inconsistencies in APIs, and completes the documentation of the major features. This release also introduces aggregations, similar to Search 5’s faceting feature.
What the Beta status means
Essentially, reaching Beta status means Hibernate Search 6 will be more stable from now on:
The most commonly used APIs are not expected to change anymore.
The implementations are well-tested and work as expected.
The reference documentation covers all common use cases and most advanced use cases, and shouldn’t change much before the final release.
It’s still a Beta, not a Candidate Release, because a significant amount of work still remains before the final release:
Some of the less commonly used features such as scrolling or error handlers are still missing.
Some improvements over Search 5 such as search analyzers or zero-downtime mass indexing are still missing.
Performance is satisfying (no obvious bottlenecks), but needs more thorough testing.
Depending on the changes needed to solve the above, we may still change the index format in later Betas, which will require reindexing.
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
Aggregation DSL
As of HSEARCH-3649, Hibernate Search 6 now offers a DSL to build aggregations, i.e. aggregated results based on all hits for a given search query.
Supported aggregations are rather simple for now, but more will be added later:
Terms aggregations produce a count of the number of hits for each value of a given field:
AggregationKey<Map<Genre, Long>> countsByGenreKey =
AggregationKey.of( "countsByGenre" );
SearchResult<Book> result = searchSession.search( Book.class )
.predicate( f -> f.matchAll() )
.aggregation( countsByGenreKey, f -> f.terms()
.field( "genre", Genre.class ) )
.fetch( 20 );
Map<Genre, Long> countsByGenre = result.getAggregation( countsByGenreKey );
Given a set of ranges, range aggregations produce a count of the number of hits for each range of values of a given field:
AggregationKey<Map<Range<Double>, Long>> countsByPriceKey =
AggregationKey.of( "countsByPrice" );
SearchResult<Book> result = searchSession.search( Book.class )
.predicate( f -> f.matchAll() )
.aggregation( countsByPriceKey, f -> f.range()
.field( "price", Double.class )
.range( 0.0, 10.0 )
.range( 10.0, 20.0 )
.range( 20.0, null )
)
.fetch( 20 );
Map<Range<Double>, Long> countsByPrice = result.getAggregation( countsByPriceKey );
This provides all the features that were provided by Hibernate Search 5’s “faceting” feature, with the exception of “drill-down”, which is straightforward to reproduce using the predicate DSL. In addition, the new aggregation feature solves several long-standing issues of faceting in Search 5:
HSEARCH-1372/HSEARCH-2111: The aggregation API uses clear, consistent naming.
HSEARCH-2472/HSEARCH-2954: Encoding is no longer limited to just numeric fields or text: fields with Java 8 date/time types can be aggregated too, for example LocalDate, and they use the dedicated date datatype in the Elasticsearch backend.
HSEARCH-1748: Attempts to create aggregations on unsupported fields will now trigger an exception during query building, instead of just returning empty results.
HSEARCH-2446: Aggregations (faceting) can now be used on fields declared by bridges.
Discrete aggregations no longer require to index numbers as text.
Version upgrades
HSEARCH-3706: Upgrade to Hibernate ORM 5.4.5.Final
Hibernate Search 6 requires ORM 5.4.4.Final or later to work correctly. Earlier 5.4.x versions will not work correctly.
Documentation
As of HSEARCH-3270, all major features of Hibernate Search 6 are documented.
Here are the sections we added or completed since the previous release:
HSEARCH-3674/HSEARCH-3675: Core concepts: full-text search, mapping and analysis
HSEARCH-3676, HSEARCH-3673, HSEARCH-2224, HSEARCH-3679: Mapping Hibernate ORM entities to indexes, especially @IndexedEmbedded, container extraction and tuning automatic reindexing.
HSEARCH-3692: Custom bridges
HSEARCH-3615: Query DSL
HSEARCH-3681: MassIndexer
Backward-incompatible API changes
There are quite a few backward-incompatible changes this time, as this was the last set of changes before the Betas.
HSEARCH-3705: The default index name for indexed entity types is now the entity name instead of the fully qualified class name.
HSEARCH-3707: The limit and offset parameters in SearchQuery.fetch(Integer, Integer) have been swapped.
HSEARCH-3669: The fetch()/fetchHits() methods are now deprecated: use fetchAll/fetchAllHits instead.
HSEARCH-3606: The SearchWriter was renamed to SearchWorkspace, and SearchSessionWritePlan was renamed to SearchIndexingPlan.
HSEARCH-3623: The syntax of analysis definition DSLs was updated:
It is no longer possible to chain analyzer/normalizer definition with the Lucene analysis definition DSL.
The methods prefixed with with in the Elasticsearch analysis definition DSL were deprecated in favor of new methods without this prefix (withTokenizer() ⇒ tokenizer()).
HSEARCH-3671: SearchScope is now session-independent. The main implication is you can no longer write scope.search(): use searchSession.search(scope) instead.
HSEARCH-3691: @GeoPointBinding can no longer be used on properties of type GeoPoint: use @GenericField instead.
HSEARCH-3687: Generic type parameters of DSL step interfaces have changed. This will only affect you if you store DSL steps in variables, which is not recommended (you should just chain calls).
HSEARCH-3708: The range predicate DSL now exposes a new syntax to define the range to match, leveraging the new Range class. The old syntax still works but it is deprecated.
HSEARCH-1347:
org.hibernate.search.mapper.pojo.dirtiness.ReindexOnUpdate was moved to org.hibernate.search.mapper.pojo.automaticindexing.ReindexOnUpdate
Package org.hibernate.search.engine.search.dsl.predicate was moved to org.hibernate.search.engine.search.predicate.dsl
Package org.hibernate.search.engine.search.dsl.sort was moved to org.hibernate.search.engine.search.sort.dsl
Package org.hibernate.search.engine.search.dsl.projection was moved to org.hibernate.search.engine.search.projection.dsl
Package org.hibernate.search.engine.search.dsl.aggregation was moved to org.hibernate.search.engine.search.aggregation.dsl
Package org.hibernate.search.backend.elasticsearch.search.dsl.predicate was moved to org.hibernate.search.backend.elasticsearch.search.predicate.dsl
Package org.hibernate.search.backend.elasticsearch.search.dsl.sort was moved to org.hibernate.search.backend.elasticsearch.search.sort.dsl
Package org.hibernate.search.backend.elasticsearch.search.dsl.projection was moved to org.hibernate.search.backend.elasticsearch.search.projection.dsl
Package org.hibernate.search.backend.elasticsearch.search.dsl.aggregation was moved to org.hibernate.search.backend.elasticsearch.search.aggregation.dsl
Package org.hibernate.search.backend.lucene.search.dsl.predicate was moved to org.hibernate.search.backend.lucene.search.predicate.dsl
Package org.hibernate.search.backend.lucene.search.dsl.sort was moved to org.hibernate.search.backend.lucene.search.sort.dsl
Package org.hibernate.search.backend.lucene.search.dsl.projection was moved to org.hibernate.search.backend.lucene.search.projection.dsl
Package org.hibernate.search.backend.lucene.search.dsl.aggregation was moved to org.hibernate.search.backend.lucene.search.aggregation.dsl
org.hibernate.search.engine.search.SearchPredicate was moved to org.hibernate.search.engine.search.predicate.SearchPredicate
org.hibernate.search.engine.search.SearchSort was moved to org.hibernate.search.engine.search.sort.SearchSort
org.hibernate.search.engine.search.SearchProjection was moved to org.hibernate.search.engine.search.projection.SearchProjection
org.hibernate.search.engine.search.DocumentReference was moved to org.hibernate.search.engine.backend.common.DocumentReference
HSEARCH-3441: DSL methods now use consistent wording.
In the programmatic mapping API:
withExtractor() was renamed to extractor()
withExtractors() was renamed to extractors()
withoutExtractors() was renamed to noExtractors()
In the predicate DSL:
onField()/orField()/onFields()/orFields() are now deprecated. Use the prefix-less versions instead (e.g. onField() ⇒ field()).
withConstantScore() is now deprecated: use constantScore() instead.
boostedTo() is now deprecated: use boost() instead.
withAndAsDefaultOperator() is now deprecated: use defaultOperator(BooleanOperator) instead.
withSlop() is now deprecated: use slop() instead.
In the sort DSL:
Methods prefixed with by are now deprecated. Use the prefix-less versions instead (e.g. byField() ⇒ field()).
onMissingValue() is now deprecated: use missing() instead.
sortLast() is now deprecated: use last() instead.
sortFirst() is now deprecated: use first() instead.
HSEARCH-859: Some configuration properties were changed for better consistency.
Configuration properties that were simply renamed:
hibernate.search.backends.myBackend.analysis_configurer → hibernate.search.backends.myBackend.analysis.configurer
hibernate.search.backends.myBackend.multi_tenancy_strategy → hibernate.search.backends.myBackend.multi_tenancy.strategy
hibernate.search.mapping_configurer → hibernate.search.mapping.configurer
hibernate.search.enable_annotation_mapping → hibernate.search.mapping.process_annotations
hibernate.search.autoregister_listeners → hibernate.search.enable
hibernate.search.enable_configuration_property_tracking was renamed to hibernate.search.configuration_property_checking.strategy and expected values also changed: default is warn, use ignore to disable checks.
Enums for configuration properties were relocated to appropriate packages.
Property keys listed in *Settings classes now include the hibernate.search. prefix where relevant. Use *Settings.Radicals for property keys without any prefix.
Other improvements and bug fixes
HSEARCH-3667: Hibernate Search 6 now works correctly when Hibernate Envers is enabled: it boots correctly and is able to index the latest version of versioned entities. Thanks to Damien Clement d’Huart for reporting this and providing a fix.
HSEARCH-2254: Single-valued sorts on fields within nested fields now work correctly.
HSEARCH-3715: It is once again possible to set a custom monitor when mass indexing.
HSEARCH-3670: java.util.Date properties holding a java.sql.Date value will now be correctly indexed.
HSEARCH-3690: Entity identifiers of type string are now correctly supported.
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)