Wildfly server provisioning elastic search integration

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



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


    

        

        

        

    

And finally in your pom.xml file add the plugin below:


    org.wildfly.build
    wildfly-server-provisioning-maven-plugin
    1.2.6.Final
    
        
        server-provisioning
        
            build
        
        compile
        
            server-provisioning.xml
            wildfly-with-updated-hibernate-search
        
        
    

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:


 javax.persistence
 javax.persistence-api
 2.2

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:



 org.hibernate
 hibernate-search-elasticsearch
 5.10.3.Final



 org.elasticsearch
 elasticsearch
 6.2.3

Make some minor tweaks to persistence.xml





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:

  • There are 3 errors with the elasticsearch integration related to JSON.
  • If you want to try lucene, just modify the configuration in test-persistence.xml.

You may also want to check:

Leave a Reply