We just published Hibernate Search 6.0.0.Beta6.
Aside from several bugfixes, this release mainly introduces schema management configuration and API at the mapper level, sorts on multi-valued fields, simpler and configurable indexing queues, implicit nested predicates, and offline startup for Elasticsearch. It also includes upgrades to Lucene 8.5, Elasticsearch 7.6.1 and Hibernate ORM 5.4.13.Final.
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.
The simpler approach of managing indexes/schemas implicitly, on startup,
through a pre-configured strategy, is now configured at the mapper level
through the configuration property
Several strategies are available:
See automatic schema management
for more information.
The default strategy for automatic schema management is now
A new approach is to manage indexes/schemas explicitly, whenever you want after startup.
It involves getting a
from Hibernate Search, then calling its methods to create, validate, or even drop the schema on-demand:
SearchSchemaManager manager = Search.mapping( sessionFactory ) .scope( MyEntity.class ) // Use `Object.class` to target all indexed entity types .schemaManager(); manager.dropAndCreate(); // Starting here, the freshly created indexes can be used
See manual schema management for more information.
Finally, indexes and schema can simply be dropped and re-created when reindexing,
by setting the new
dropAndCreateSchemaOnStart(boolean) option on the
See MassIndexer parameters for more information.
Thanks to the efforts of Alexis Cucumel (HSEARCH-3841), it is now possible to start Hibernate Search in fully offline mode.
To that end:
Configure the expected version of the Elasticsearch cluster using the property
hibernate.search.backends.<backend name>.version, and disable version checks on startup using the property
Disable automatic schema management on startup by setting the property
If necessary, add explicit schema management code to your application that you will trigger when you know the Elasticsearch cluster is up and running.
As of HSEARCH-3103, Hibernate Search is now capable of sorting on multi-valued fields. By default, the minimum value of each document will be picked for ascending sorts, and the maximum value for descending sorts.
mode(SortMode) method in the sort DSL can be used to tell Hibernate Search
how to pick the value to sort on:
List<Author> hits = searchSession.search( Author.class ) .where( f -> f.matchAll() ) .sort( f -> f.field( "books.pageCount" ).mode( SortMode.AVG ) ) .fetchHits( 20 );
See this section of the documentation for more information.
Thanks to Waldemar Kłaczyński for contributing the implementation.
Up until now, using the "nested" storage for object fields meant that you had to wrap every predicate
accessing one if its sub-fields with a
nested predicate, even when there was just one predicate.
As of HSEARCH-3752, Hibernate Search does that for you: nested predicates are now added implicitly when not mentioned explicitly.
This means that this query:
List<Book> hits = searchSession.search( Book.class ) .where( f -> f.nested().objectField( "authors" ) .nest( f.match().field( "authors.lastName" ) .matching( "asimov" ) ) .fetchHits( 20 );
... can now be simply written like this (which previously wouldn’t have matched anything):
List<Book> hits = searchSession.search( Book.class ) .where( f -> f.match().field( "authors.lastName" ) .matching( "asimov" ) ) .fetchHits( 20 );
If you actually need a condition with more than one predicate on the same nested object,
you still need to wrap the predicates in a
List<Book> hits = searchSession.search( Book.class ) .where( f -> f.simpleQueryString().field( "title" ) .matching( "I want a **robot**" ) .flags( SimpleQueryFlag.AND, SimpleQueryFlag.OR, SimpleQueryFlag.NOT ) ) .fetchHits( 20 );
Indexing in Hibernate Search involves pushing operations to queues, and executing these operations in background threads.
In HSEARCH-3822 and HSEARCH-3872, we implemented several improvements to the orchestration of indexing operations, enabling parallel indexing for a single index in particular, and generally simplifying the code.
Finally, in order to make the most of parallel indexing, in HSEARCH-3871 we switched the default configuration of commits in the Lucene backend: commits are now performed every second when mass indexing, instead of the previous behavior of committing every ~1000 documents.
Hibernate Search 6 requires ORM 5.4.4.Final or later to work correctly. Earlier 5.4.x versions will not work correctly.
The internal docvalues format for sortable fields in the Lucene backend has changed. Re-indexing will be necessary if your index contains sortable fields.
Configuration properties relative to Elasticsearch index lifecycle management have changed:
The configuration property
lifecycle.strategywas removed and will trigger an exception on startup if used. For automatic schema management on startup, see the new
schema_managementoptions at the mapper level.
The configuration property
lifecycle.minimal_required_statuswas renamed to
The configuration property
lifecycle.minimal_required_status_wait_timeoutwas renamed to
A few more features in the Sort DSL are now documented:
@IndexedEmbeddedcan now be applied multiple times to the same getter/field. You will simply need a different
HSEARCH-3844: Using the simple query string predicate on non-analyzed, non-normalized fields in the Lucene backend no longer triggers a
NullPointerException. Thanks to Waldemar Kłaczyński for reporting this.
HSEARCH-3845: Prefix queries generated by the simple query string predicate in the Lucene backend no longer skip normalization of the input text. Thanks to Waldemar Kłaczyński for reporting and fixing this.
ConcurrentModificationExceptionused to be thrown in very specific scenarios when indexing multiple entities with
@IndexEmbeddeddependencies; this was fixed. Thanks to Alexis Cucumel for reporting and fixing this.
float-based fields in the Lucene backend no longer place documents around
0, but place them last/first as was originally intended.
HSEARCH-3861: Elasticsearch search queries no longer needlessly fetch the whole document source when no explicit projection is defined.
HSEARCH-3869: Failure in Elasticsearch bulk works no longer lead to a
@IdClasson an entity (even not
@Indexed), no longer leads to a
NullPointerExceptionwhen bootstrapping Hibernate Search.
And more. For a full list of changes since the previous releases, please see the release notes.
All details are available and up to date on the dedicated page on hibernate.org.