Hibernate Search with Spring Data on Pivotal CF revisited

Hibernate Search has become final with 5.8.0 / 5.8.1
October 6, 2017 by Michael

About a year ago I published an article called Running Hibernate Search with Elasticsearch on Pivotal CF. In several projects I use Hibernate Search. If you’re already have Hibernate-JPA-Entities in your project and you need a full text index for some of them, its really easy to add a Lucene based index by just using some simple annotations in addition to your standard JPA annotations. I also have a post on that topic, check Hibernate Search and Spring Boot: Simple yet powerful archiving.

You can now run Hibernate Search against a local disk based Lucene index as well as against the full blown Elasticsearch index. Together with Spring Data JPA repositories it’s a really valuable tool.

Back in September, Sanne announced the general availably of Hibernate Search 5.8, read it here. It now supports an even broader range of Elasticsearch and also introduces the nice feature of using a Simple Query String.

While upgrading the EuregJUG archive, I ran into two little problems. One got fixed nearly immediately after I reported it (see HSEARCH-2883) and the other one was more on my site.

The EuregJUG site runs on Pivotal Cloud Foundry using an Elasticsearch instance from the marketplace. The PaaS gives me the connection URL including user name and password in the form of user:password@host which is perfectly valid. Sadly that isn’t supported by Hibernate Search anymore.

In the process of splitting the environment variable I have I came across Springs EnvironmentPostProcessor interface. This interface can be used to change the environment after all possible property sources have been evaluated. To make this work, you have to declare it in META-INF/spring.factories. You’ll find the relevant parts here (the declaration to make Spring load this instance early) and the actual implementation (not fancy, just splitting a string). I really like the notion of the Environment post processor. I have every property ready to use and can force some of them to be in a format expected for a third party tool. Could be useful in a starter as well.

With that little change I have a nice search system in place, look for example for everything Spring and Mark. This is how simple the snippet from the extended Spring Data repository looks:

Thanks for the very nice work, Sanne, Yoann and Ales!

No comments yet

Post a Comment

Your email is never published. We need your name and email address only for verifying a legitimate comment. For more information, a copy of your saved data or a request to delete any data under this address, please send a short notice to michael@simons.ac from the address you used to comment on this entry.
By entering and submitting a comment, wether with or without name or email address, you'll agree that all data you have entered including your IP address will be checked and stored for a limited time by Automattic Inc., 60 29th Street #343, San Francisco, CA 94110-4929, USA. only for the purpose of avoiding spam. You can deny further storage of your data by sending an email to support@wordpress.com, with subject “Deletion of Data stored by Akismet”.
Required fields are marked *