Wildfly server provisioning elastic search integration
Tech-Today

Wildfly server provisioning elastic search integration


I'm interested and would like to evaluate the integration of Elasticsearch to hibernate-search. I'm using the Wildfly container, however, Wildfly's hibernate-search library is a bit outdated: 5.5.8. so I need to find a way to outdate the jars and that's what led me to WF's server-provisioning using feature pack which is well explained here https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#updating-wildfly-hibernatesearch-versions

As stated you need to add the lines below to your persistence.xml
<property name="jboss.as.jpa.providerModule" value="org.hibernate:5.3" />
<property name="wildfly.jpa.hibernate.search.module" value="org.hibernate.search.orm:5.10.3.Final" />

Then you need to create a file named server-provisioning.xml in your project's root folder:

<server-provisioning xmlns="urn:wildfly:server-provisioning:1.1" copy-module-artifacts="true">
<feature-packs>

<feature-pack
groupId="org.hibernate"
artifactId="hibernate-search-jbossmodules-orm"
version="5.10.3.Final"/>

<feature-pack groupId="org.hibernate"
artifactId="hibernate-search-jbossmodules-elasticsearch" version="5.10.3.Final" />

<feature-pack
groupId="org.wildfly"
artifactId="wildfly-feature-pack"
version="13.0.0.Final" />

</feature-packs>
</server-provisioning>
And finally in your pom.xml file add the plugin below:
<plugin>
<groupId>org.wildfly.build</groupId>
<artifactId>wildfly-server-provisioning-maven-plugin</artifactId>
<version>1.2.6.Final</version>
<executions>
<execution>
<id>server-provisioning</id>
<goals>
<goal>build</goal>
</goals>
<phase>compile</phase>
<configuration>
<config-file>server-provisioning.xml</config-file>
<server-name>wildfly-with-updated-hibernate-search</server-name>
</configuration>
</execution>
</executions>
</plugin>
It should create a new folder in your target's directory named wildfly-with-updated-hibernate-search. And you should re-configure this server for your needs: datasource, mail, cache, etc. Make sure that it contains the jar files inside modules folder. The setting above copy-module-artifacts="true" should do it, notice that in the hibernate-search documentation, this property is not initialized. Thus, I spent some hours how to obtain the jars (I even downloaded some :-)).
It works for a basic requirement, but I still found some errors though like:
Caused by: java.lang.NoClassDefFoundError: javax/persistence/TableGenerators
Which should be solved by adding:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>

But that does not solve the issue so I added the -Dee8.preview.mode=true parameter and that did the trick.

Well, you may just want to wait for the release of Wildfly14.

Changes for Elasticsearch

In your project dependency add:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-elasticsearch</artifactId>
<version>5.10.3.Final</version>
</dependency>

<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>6.2.3</version>
</dependency>

Make some minor tweaks to persistence.xml
<property name="hibernate.search.default.indexmanager" value="elasticsearch" />
<property name="hibernate.search.default.elasticsearch.host" value="http://127.0.0.1:9200" />
<property name="hibernate.search.default.elasticsearch.index_schema_management_strategy" value="CREATE" />

Run elasticsearch in docker https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html. Make sure that the status of your elasticsearch server is green. See docker-compose.yml in the project mentioned below.

Run your application. You should be able to see logs in elasticsearch that verifieds the data posted.

You may want to check the complete code accessible at https://github.com/czetsuya/hibernate-search-demo. Switch to latest-hibernate-search branch.

Note:



You may also want to check:




- Hibernate Ogm For Mongodb
So lately I've been playing with Hibernate OGM MongoDB's latest version 5.4.0.Beta2 but I'm not able to run a demo project created from wildfly-javaee7-war archetype following the documentation. Here are the changes I've made to make...

- How To Generate Jax-rs Documentation Using Maven
To generate the jax-rs documentation automatically using maven, we need to add some plugins in the build section of the project's pom file. To avoid running this plugin every time you invoke mvn install, you can create a separate profile for it. Here's...

- A Maven Project That Have Multiple Property Files Via Maven Antrun Plugin
This tutorial will answer several questions (below) within a maven project that has several configuration files (dataset, property, persistence). 1.) How to have multiple persistence, datasource and property files depending on the profile or environment...

- How To Add Pmd Reporting To Maven
Before proceeding to this exercise, you may want to try my tutorial on how to setup a maven project to eclipse: http://czetsuya-tech.blogspot.com/2012/04/how-to-create-modularized-maven-project.html. Assuming you have follow the tutorial above, you should...

- Java.lang.nosuchmethodexception: Org.hibernate.validator.classvalidator
Note I'm using jboss-5.1.0.GA If you ever encounter the following error: Caused by: org.hibernate.AnnotationException: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.(java .lang.Class, java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator,...



Tech-Today








.