【问题标题】:Spring Boot + Hibernate Search: Required Index Status Ignored?Spring Boot + Hibernate Search:忽略所需的索引状态?
【发布时间】:2020-05-17 05:28:19
【问题描述】:

连接 Hibernate Search 到 Elasticsearch,我注意到当我部署一个非 ES 时,我的服务不会连接成功。在我看来,设置 required_index_status 的环境变量被忽略了。我正在寻找一个错字或类似的东西半小时,但找不到任何东西。

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

环境变量:

$ 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

日志消息 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.

记录消息 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
}

我们可以清楚地看到它正在等待状态“绿色”而不是“黄色”。

【问题讨论】:

  • 这可能不相关,但是 1. 你应该使用工件 ID hibernate-search-orm 而不是 hibernate-search 和 2. 你应该为 hibernate-search-ormhibernate-search-elasticsearch 使用相同的版本。

标签: spring-boot elasticsearch hibernate-search


【解决方案1】:

我相信您的环境变量 SPRING_JPA_PROPERTIES_HIBERNATE_SEARCH_DEFAULT_ELASTICSEARCH_REQUIRED_INDEX_STATUS 正在被转换为 spring.jpa.properties.hibernate.search.default.elasticsearch.required.index.status,而它应该被转换为 spring.jpa.properties.hibernate.search.default.elasticsearch.required_index_status(注意末尾附近的下划线)。

我不知道 Spring 是如何准确翻译环境变量名的,但一定有办法避开下划线。也许是双下划线?您可能应该看看他们的文档。

最坏的情况,您可以将spring.jpa.properties.hibernate.search.default.elasticsearch.required_index_status 设置为application.properties 中的自定义环境变量,然后设置该自定义环境变量而不是您所做的。

【讨论】:

  • 我怀疑这也是一个问题,但我读了stackoverflow.com/questions/34178556/…,因此认为它应该是正确的。我将尝试自定义环境变量,看看会发生什么,以便我们获得更多数据。
猜你喜欢
  • 2017-06-14
  • 2018-02-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-25
  • 2019-11-28
  • 1970-01-01
相关资源
最近更新 更多