{{announcement.body}}
{{announcement.title}}

Deploy Quarkus Faster in the Cloud with Platform.sh. Part 4: Hibernate Search With Elasticsearch

DZone 's Guide to

Deploy Quarkus Faster in the Cloud with Platform.sh. Part 4: Hibernate Search With Elasticsearch

How to deploy a Hibernate Search Quarkus application in the cloud with Platform.sh

· Java Zone ·
Free Resource

Quarkus is, in its own words, a Cloud Native, (Linux) Container First framework for writing Java applications. It has become popular because of the amazingly fast boot time, incredibly low RSS memory. In this series of articles about Quarkus, we'll teach you how to deploy Quarkus with Hibernate search with Elasticsearch.

Full-text searching provides the capability to identify natural-language documents that satisfy a query, and optionally to sort them by relevance to the query.  Hibernate Search automatically extracts data from Hibernate ORM entities to push it to local Apache Lucene indexes or remote Elasticsearch indexes.

The first step is to create the application itself, and Quarkus has proper documentation. You have either a Maven Archetype or the start code link where you can define the dependencies that you need to write your application.

In the maven project, we either add manually or from the start site the Hibernate Panache ORM, Hibernate Search,  JDBC driver, and the data source dependency.

XML


We need to configure the application to run locally to test it.

Properties files


If you want to run both PostgreSQL and Elasticsearch locally, a good option might be Docker. You can run that with the command below:

Shell


The infrastructure code is ready; the next step is to create the application itself. In this sample, we'll create a small rest-application to manage a simple music store and search from the lyrics.

First, let’s create our Music entity; on this sample, we'll use an active record with Panache.

Java


In the entity, we set up several annotations beyond the JPA. It defines the search engine with Hibernate search. The analysis is a big part of full-text search: it defines how the text will be processed when indexing or building search queries. There are a lot of bundled analyzers, but you can also develop your own for your own specific purposes. 

You can learn more about the Elasticsearch analysis framework in the Analysis section of the Elasticsearch documentation.

It is an easy task. We just need to create an implementation of ElasticsearchAnalysisConfigurer (and configure Quarkus to use it, more on that later).

Java


The last step is to create a resource where the client can do a request and perform CRUD operations. As we can see, with Panache, we can reduce a lot of complexity of the code. 

In our existing resource, different from the third series, we include two more methods. The first one is designed to load the information and index the info to Elasticsearch. The second is designed to use the powerful engine of Hibernate Search integrated with Elasticsearch.

Java


The application is ready to go. You can run the test on the application. The next step is to move to the cloud with Platform.sh.

To move your application to the cloud, you need three files:

YAML


Platform.sh allows you to completely define and configure the topology and services you want to use on your project. This sample code uses PostgreSQL and Elasticsearch.

YAML


You control your application and the way it will be built and deployed on Platform.sh via a single configuration file. This application will grant permission to access both PostgreSQL and Elasticsearch.

YAML


The application is now ready, so it’s time to move it to the cloud with Platform.sh using the following steps:

  • Create a new free trial account.
  • Sign up with a new user and password, or login using a current GitHub, Bitbucket, or Google account. If you use a third-party login, you’ll be able to set a password for your Platform.sh account later.
  • Select the region of the world where your site should live.
  • Select the blank template.

You have the option to either integrate to GitHub, GitLab, or Platform.sh will provide to you. Finally, push to the remote repository.

Done! We have a simple and nice Quarkus application ready to go to the cloud.

Topics:
cloud ,elasticsearch ,hibernate ,java ,platform.sh ,quarkus ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}