Skip to content

Better support for hibernate search with embedded elastic search #6333

@jkirsch

Description

@jkirsch

This is a feature request.

Using an embedded instance of elastic search that should be used by hibernate search in a spring boot autoconfigured environment exhibits a race condition.
Elastic search starts in the background and when hibernate gets initialized it tries to connect to elastic search, which it is not up yet, thus the app fails to start.

How to reproduce

Using spring boot 1.4.0.M3 and the following additional JPA dependencies. Assuming @Field annotations on the jpa entity classes.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
    <version>1.4.0.M3</version>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
        <artifactId>hibernate-search-backend-elasticsearch</artifactId>
        <version>5.6.0.Alpha3</version>
</dependency

Using the following properties

spring.data.elasticsearch.properties.http.enabled= true
spring.jpa.properties.hibernate.search.default.indexmanager= elasticsearch
spring.jpa.properties.hibernate.search.elasticsearch.index_management_strategy= CREATE_DELETE

It only works, when index_management_strategy is set to none which skips the initial index configuration. But this means during hibernate setup nothing is send to elastic search, only later when new entities are created. At that time elastic search has finished loading and it works. But unfortunately, because no index has been configured, it uses the default index, which cannot be configured from the properties, thus misses any special Analyzer or Tokenizer set on the entity classes.

Why would one want that?

It is nice to configure everything together for integration tests. Furthermore, I'm deploying as a fat jar into openshift, so having only one jar to manage eases deployment - instead of starting elastic search separately.

The problem

The problem comes from the background initialization of elastic search, it finishes initialization, even though its not up yet.

How to solve

Not sure, I posted the question on stackoverflow without success.
Potentially there should be some form of a busy wait on elastic search being up (responds to host:9200) during the autoconfiguration process

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions