7/31/22, 7:26 PM ORM. Lucene. Elasticsearch. Integrated.
- Hibernate Search
Hibernate Search
ORM. Lucene. Elasticsearch.
Integrated.
Getting
started
Latest
stable (6.1)
Development
(6.2)
Automatic indexing of Hibernate ORM entities into Apache Lucene or Elasticsearch.
Advanced search API: full-text, geospatial, aggregations and more.
Full-text search for entities
Hibernate Search automatically extracts data from Hibernate ORM entities
to push it to local Apache Lucene indexes or
remote Elasticsearch/OpenSearch indexes.
It features:
Declarative mapping of entity properties to index fields, either
through annotations or a programmatic API.
On-demand mass indexing of all entities in the database, to
initialize the indexes with pre-existing data.
On-the-fly automatic indexing of entities modified through a
Hibernate ORM session, to always keep the indexes up-to-date.
A Search DSL to easily build full-text search queries and retrieve the
hits as Hibernate ORM entities.
And much more! (see below)
For example, map your entities like this:
@Entity
// This entity is mapped to an index
@Indexed
public class Book {
// The entity ID is the document ID
https://hibernate.org/search/ 1/6
7/31/22, 7:26 PM ORM. Lucene. Elasticsearch. Integrated. - Hibernate Search
@Id
@GeneratedValue
private Integer id;
// This property is mapped to a document field
@FullTextField
private String title;
@ManyToMany
// Authors will be embedded in Book documents
@IndexedEmbedded
private Set<Author> authors = new HashSet<>();
// Getters and setters
// ...
@Entity
public class Author {
@Id
@GeneratedValue
private Integer id;
// This property is mapped to a document field
@FullTextField
private String name;
@ManyToMany(mappedBy = "authors")
private Set<Book> books = new HashSet<>();
// Getters and setters
// ...
Index pre-existing data like this:
SearchSession searchSession = Search.session( entityManager );
MassIndexer indexer = searchSession.massIndexer( Book.class );
indexer.startAndWait();
Automatic indexing does not require any change to code based on JPA or
Hibernate ORM:
Author author = new Author();
author.setName( "Isaac Asimov" );
Book book = new Book();
book.setTitle( "The Caves Of Steel" );
book.getAuthors().add( author );
author.getBooks().add( book );
entityManager.persist( author );
entityManager.persist( book );
And search like this:
https://hibernate.org/search/ 2/6
7/31/22, 7:26 PM ORM. Lucene. Elasticsearch. Integrated. - Hibernate Search
SearchResult<Book> result = Search.session( entityManager )
.search( Book.class )
.where( f -> f.match()
.fields( "title", "authors.name" )
.matching( "Isaac" ) )
.fetch( 20 );
List<Book> hits = result.hits();
long totalHitCount = result.total().hitCount();
Full control
Unlike with web search, this is your data, your domain, your application,
stored wherever you decide.
You can choose what to index (and how to index it) very precisely with per-
property mapping and go even further with custom bridges.
You also have far better control on how your data is processed
with configurable analysis, so you can:
Tune text processing for specific languages.
Tune text processing for domain specific terminology (e.g. medical
terms, custom acronyms expansion, …).
Control the ranking process: which results are more important.
Easy yet powerful
Designed to be easy to use from the ground up. Handles schema
initialization, indexing and query syntax transparently while you focus on
the business side of your search.
The Search DSL exposes many different predicates and sorts through a
succinct, easy-to-use API.
And if you need to go beyond, it won’t stop you: native Lucene
Queries or Elasticsearch JSON can be inserted right in the middle of
Search DSL queries.
Local or distributed
While you’ll find that performance of a "single box" based on Apache
Lucene is exceptional, you can also scale out by distributing your
application and relying on an Elasticsearch cluster for indexing, with only a
few configuration changes.
Spatial queries
https://hibernate.org/search/ 3/6
7/31/22, 7:26 PM ORM. Lucene. Elasticsearch. Integrated. - Hibernate Search
Indexing geo-localized entities is as easy as adding
the @GenericField annotation.
Filter results around a certain location like the user position, and use
a distance sort to pull to the top the matching pizzerias which are closest to
the user.
Aggregations
Get search results aggregated by groups and categories.
For example webshops will want to show all hits, but also display a count
of hits by price range and brand.
Latest news
Hibernate Search
6.2.0.Alpha1 is out
2022-07-12
We just published
Hibernate Search
6.2.0.Alpha1, an alpha
release of the next minor
version of Hibernate
Search. The main feature of
this new version is the new
Standalone...
Hibernate Search
6.1.5.Final released
2022-05-11
We just published a
maintenance release for
Hibernate Search:
6.1.5.Final. This release
mainly upgrades to
Hibernate ORM 5.6.8.Final,
upgrades to Hibernate
ORM 6.0.1.Final for -orm6
artifacts, upgrades to the...
Hibernate Search
6.1.4.Final released
2022-04-07
We just published a
maintenance release for
Hibernate Search:
https://hibernate.org/search/ 4/6
7/31/22, 7:26 PM ORM. Lucene. Elasticsearch. Integrated. - Hibernate Search
Hibernate Search:
6.1.4.Final. This release
mainly upgrades to
Hibernate ORM 6.0.0.Final
for -orm6 artifacts,
upgrades to the latest
version of Jakarta...
Hibernate Search
6.1.3.Final and
6.0.9.Final released
2022-03-18
We just published two
maintenance releases for
Hibernate Search:
6.1.3.Final and 6.0.9.Final.
These releases mainly
upgrade Hibernate Search
to the latest compatible
Hibernate ORM versions,
and fix a...
Hibernate Search
6.1.1.Final released
2022-02-08
We just published a
maintenance release for
Hibernate Search:
6.1.1.Final. What’s new
HSEARCH-4462: Upgrade
to Hibernate ORM
5.6.5.Final HSEARCH-
4468: Upgrade to slf4j
1.7.35 in hibernate-search-
backend-elasticsearch-aws
HSEARCH-4465: Upgrade
-orm6 artifacts to Hibernate
ORM...
Hibernate Search
6.1.0.Final is out!
2022-01-25
We just published
Hibernate Search
6.1.0.Final! The most
important change by far in
Hibernate Search
6.1.0.Final is support for
h
https://hibernate.org/search/
di t ib t d 5/6
7/31/22, 7:26 PM ORM. Lucene. Elasticsearch. Integrated. - Hibernate Search
asynchronous, distributed
automatic indexing through
the outbox-polling
coordination strategy. But...
https://hibernate.org/search/ 6/6