2

I want to add a full text search functionality to my Spring Boot application, data should be stored in an SQL database, I also read that using ES as a primary database is not recommended. One way I thought of is: create, update and delete operations can be done on both the primary SQL database and in ES (which we can do using the Java High Level REST Client), for example, when inserting a row in SQL, we index it in ES as well, then we perform searches using Elasticsearch. I think we can also use Hibernate search. Is it the right approach? Otherwise any suggestions?

Ala Abid
  • 2,256
  • 23
  • 35
  • This might be of interest to you: https://stackoverflow.com/q/47918507/6692043 – yrodiere Feb 27 '19 at 07:14
  • Indeed it is. So what I understood is, Hibernate Search will only use Elasticsearch as an Index, and still store data using JPA in the primary SQL database. – Ala Abid Feb 27 '19 at 07:48
  • 1
    In essence, yes. Technically Hibernate Search doesn't write anything to your database: you do, through JPA and Hibernate ORM, and Hibernate Search will automatically update the Elasticsearch index to mirror the content of your database. – yrodiere Feb 27 '19 at 11:03

2 Answers2

1

If you need only simple full text search consider postgresql, I'am using it for indexing and search document content: https://www.postgresql.org/docs/9.1/textsearch-controls.html .

  • I also need fuzzy search, completion suggestions, highlighting and ranking... not sure if PostgreSQL can do that. – Ala Abid Feb 26 '19 at 15:57
1

The main difference is that Hibernate Search provides integration between JPA and your index of choice (Lucene or Elasticsearch):

Hibernate Search will automatically add/update/delete documents in your full-text index according to changes in your JPA entities (as soon as you commit a transaction). Hibernate Search will allow your to build a full-text query (full-text world), and retrieve the results as managed entities (JPA world). As far as I understand, Spring-Data-Elasticsearch is focused on accessing Elasticsearch and has no JPA integration whatsoever. That is to say, you can use Spring-Data-JPA, and you can use Spring-Data-Elasticsearch, but they won't communicate with each other. You will have two separate models, which you will update and query separately.

Some other elements:

If you don't need a distributed index, Hibernate Search can run in embedded Lucene mode, without all the Elasticsearch stack. It will probably be more lightweight. Hibernate Search is currently not very flexible when it comes to customizing your Elasticsearch mapping or using advanced Elasticsearch features, because of the abstraction layer. That will change in the future, though (Hibernate Search 6). A Spring-Data-HibernateSearch module is in the works, allowing to benefit from the best of both worlds. It hasn't been released yet and is not really well documented yet, though: https://github.com/snowdrop/spring-boot-hibernate-search-booster