This repository shows how to connect from a pure Hibernate application to elasticsearch.
You can look at the different branches:
- pure hibernate
- direct connection to elasticsearch
- connection to elasticsearch using hibernate search
To run the project:
git checkout <00-legacy|01-elasticsearch|02-hibernatesearch>
mvn clean install
You should see something like:
[INFO] --- maven-failsafe-plugin:2.19.1:integration-test (default) @ hibernate-search-with-elasticsearch-tia ---
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.hibernate.demos.HibernateSearchWithDbIT
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.202 sec - in org.hibernate.demos.HibernateSearchWithDbIT
Results :
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
Main files you should look at:
- POM file:
pom.xml
- Configuration:
src/main/resources/META-INF/persistence.xml
- Top entity:
src/main/java/org/hibernate/demos/hswithes/model/VideoGame.java
- Tests:
src/test/java/org/hibernate/demos/HibernateSearchWithDbIT.java
When using docker, you can run the es.sh
script. Basically it does:
#! /bin/sh
docker stop hsearch_es
docker rm hsearch_es
docker run -p 9200:9200 -p 9300:9300 -d --name hsearch_es elasticsearch:2.4
docker logs -f hsearch_es
When done, you can stop the docker instance:
docker stop hsearch_es