Skip to content

Hibernate Search is a library that allows keeping your local Lucene indexes or ElasticSearch cluster in sync with your Database

Notifications You must be signed in to change notification settings

hakdogan/hibernate-search

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Hibernate Search

Quality Gate Status Maintainability Rating Reliability Rating Coverage

Hibernate Search is a library that allows keeping your local Apache Lucene indexes or ElasticSearch cluster in sync with your data that extracts from Hibernate ORM based on your domain model. This repository was created for an article published in the Java Advent Calendar and shows you how to use Hibernate Search in a concrete example.

Prerequisites

  • JDK 1.8 or later
  • Maven 3.x.x
  • Docker for Elasticsearch and PostgreSQL

Preparing the infrastructure

The entities of the application are stored in PostgreSQL and indexed in ElasticSearch so we need instances of them.

docker run --rm --name postgresql \
  -e POSTGRES_USER=postgres \ 
  -e POSTGRES_PASSWORD=postgres \ 
  -e POSTGRES_DB=jugistanbul \ 
  -p 5432:5432 \ 
  postgres:${POSTGRESQL_VERSION}
docker run --rm --name elasticsearch  \
  -e "discovery.type=single-node" \
  -p 9200:9200 \ 
  docker.elastic.co/elasticsearch/elasticsearch-oss:${ELASTICSEARCH_VERSION}

Usage examples

http -v GET localhost:8080/search/event/quarkus
GET /search/event/Quarkus HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/2.3.0



HTTP/1.1 200 OK
Content-Length: 43
Content-Type: application/json

[
  {
    "id": 3,
    "name": "Introduction to Quarkus"
  }
]

http -v GET localhost:8080/search/host/title/consultion
GET /search/host/title/consultion HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/2.3.0



HTTP/1.1 200 OK
Content-Length: 187
Content-Type: application/json

[
  {
    "events": [
                {
                  "id": 2,
                  "name": "CI & CD with Azure Devops"
                },
                {
                  "id": 3,
                  "name": "Introduction to Quarkus"
                }
              ],
              "id": 2,
              "firstname": "Huseyin",
              "lastname": "Akdogan",
              "title": "Expert Software Consultant"
  }
]

http -v GET localhost:8080/search/event/quar
GET /search/event/Quar HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/2.3.0



HTTP/1.1 404 Not Found
Content-Length: 91
Content-Type: application/json

{
    "code": 404,
    "error": "No event found",
    "exceptionType": "javax.ws.rs.WebApplicationException"
}

To run

mvn quarkus:dev

To tests

mvn verify

Relevant article

How to Keep Elasticsearch in Sync with Relational Databases?

About

Hibernate Search is a library that allows keeping your local Lucene indexes or ElasticSearch cluster in sync with your Database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages