0

Connecting Hibernate Search to Elasticsearch, I noticed that when I deploy a single not ES, my service won't connect successfully. It appears to me the environment variable to set required_index_status is being ignored. I am looking for a typo or something similar for half an hour now but cannot find anything.

pom.xml

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.7.RELEASE</version>
</parent>
...
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-search</artifactId>
    <version>5.11.1.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-search-elasticsearch</artifactId>
    <version>5.11.0.Final</version>
</dependency>

application.yml

spring: 
  data:
    rest:
      basePath: /
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: false

Environment variables:

$ kubectl describe pod <NAME>

Environment:
  ...
  SPRING_JPA_PROPERTIES_HIBERNATE_SEARCH_DEFAULT_INDEXMANAGER:                         elasticsearch
  SPRING_JPA_PROPERTIES_HIBERNATE_SEARCH_DEFAULT_ELASTICSEARCH_HOST:                   elasticsearch
  SPRING_JPA_PROPERTIES_HIBERNATE_SEARCH_DEFAULT_ELASTICSEARCH_REQUIRED_INDEX_STATUS:  yellow

Log message 1:

Caused by: org.hibernate.search.exception.SearchException: HSEARCH400024: Timed out while waiting for for index 'myindex' to reach status 'green'; status was still 'yellow' after 10000ms.

Log message 2:

Caused by: org.hibernate.search.exception.SearchException: HSEARCH400007: Elasticsearch request failed.
Request: GET /_cluster/health/myindex with parameters {wait_for_status=green, timeout=10000ms}
Response: 408 'Request Timeout' with body
{
  "cluster_name": "my-elastic-cluster",
  "status": "yellow",
  "timed_out": true,
  "number_of_nodes": 1,
  "number_of_data_nodes": 1,
  "active_primary_shards": 5,
  "active_shards": 5,
  "relocating_shards": 0,
  "initializing_shards": 0,
  "unassigned_shards": 5,
  "delayed_unassigned_shards": 0,
  "number_of_pending_tasks": 0,
  "number_of_in_flight_fetch": 0,
  "task_max_waiting_in_queue_millis": 0,
  "active_shards_percent_as_number": 50.0
}

We can clearly see it's waiting for status "green" instead of "yellow".

user3235738
  • 335
  • 4
  • 22
  • It's probably unrelated, but 1. you should use the artifact ID `hibernate-search-orm` instead of `hibernate-search` and 2. you should use the same version for `hibernate-search-orm` and `hibernate-search-elasticsearch`. – yrodiere Feb 03 '20 at 07:34

1 Answers1

0

I believe your environment variable SPRING_JPA_PROPERTIES_HIBERNATE_SEARCH_DEFAULT_ELASTICSEARCH_REQUIRED_INDEX_STATUS is being translated to spring.jpa.properties.hibernate.search.default.elasticsearch.required.index.status, whereas it should be translated to spring.jpa.properties.hibernate.search.default.elasticsearch.required_index_status (notice the underscores near the end).

I do not know how Spring translates environment variable names exactly, but there must be a way to escape underscores. Maybe double underscores? You should probably have a look at their documentation.

Worst case, you can set spring.jpa.properties.hibernate.search.default.elasticsearch.required_index_status to a custom environment variable in application.properties, and set that custom environment variable instead of what you did.

yrodiere
  • 9,280
  • 1
  • 13
  • 35
  • I suspected that to be a problem, too, but I read https://stackoverflow.com/questions/34178556/how-to-set-a-spring-boot-property-with-an-underscore-in-its-name-via-environment and therefore think it should be correct the way it is. I will try the custom environment variable and see what happens so we have more data. – user3235738 Jan 31 '20 at 14:52