如何使用休眠搜索填充 Elasticsearch

how to populate Elasticsearch with hibernate search

我正在尝试将一个使用 lucene 的项目迁移到 elasticsearch。

我正在使用:

       <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.4.1.Final</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-search-orm</artifactId>
            <version>5.11.1.Final</version>
            <scope>provided</scope>
        </dependency>
                    
        <dependency>
           <groupId>org.hibernate</groupId>
           <artifactId>hibernate-search-elasticsearch</artifactId>
           <version>5.11.8.Final</version>
        </dependency>

Elasticsearch 版本为:5.6.16

服务器 Wildfly 15

persistence.xml配置如下:

<property name="hibernate.search.default.elasticsearch.host" value="http://elasticsearch:9200"/>
<property name="hibernate.search.default.elasticsearch.username" value="elastic"/>
<property name="hibernate.search.default.elasticsearch.password" value="changeme"/>
<property name="hibernate.search.default.elasticsearch.index_schema_management_strategy" value="drop-and-create"/>

当我尝试部署应用程序时出现此错误:

app-sgrecweb_1   | 12:31:35,179 WARN  [org.hibernate.search.elasticsearch.client.impl.ServerUris] (MSC service thread 1-6) HSEARCH400073: Hibernate Search will connect to Elasticsearch server 'http://elasticsearch:9200' with authentication over plain HTTP (not HTTPS). The password will be sent in clear text over the network.
app-sgrecweb_1   | 12:31:35,501 WARN  [org.hibernate.search.indexes.impl.LuceneEmbeddedIndexFamilyImpl] (MSC service thread 1-6) HSEARCH000075: Configuration setting hibernate.search.lucene_version was not specified: using LUCENE_CURRENT.
app-sgrecweb_1   | 12:32:32,251 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-6) MSC000001: Failed to start service jboss.deployment.unit."SGREC-ear-0.1.ear".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."SGREC-ear-0.1.ear".WeldStartService: Failed to start service
app-sgrecweb_1   |  at org.jboss.msc@1.4.5.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1730)
app-sgrecweb_1   |  at org.jboss.msc@1.4.5.Final//org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1558)
app-sgrecweb_1   |  at org.jboss.threads@2.3.2.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
app-sgrecweb_1   |  at org.jboss.threads@2.3.2.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
app-sgrecweb_1   |  at org.jboss.threads@2.3.2.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
app-sgrecweb_1   |  at org.jboss.threads@2.3.2.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
app-sgrecweb_1   |  at java.base/java.lang.Thread.run(Thread.java:834)
app-sgrecweb_1   | Caused by: org.jboss.weld.exceptions.DeploymentException: HSEARCH400007: Elasticsearch request failed.
app-sgrecweb_1   | Request: GET /_cluster/health/uy.gob.sgrec.entities.sslibroactanacimiento with parameters {wait_for_status=green, timeout=10000ms}
app-sgrecweb_1   | Response: 408 'Request Timeout' with body 
app-sgrecweb_1   | {
app-sgrecweb_1   |   "cluster_name": "docker-cluster",
app-sgrecweb_1   |   "status": "yellow",
app-sgrecweb_1   |   "timed_out": true,
app-sgrecweb_1   |   "number_of_nodes": 1,
app-sgrecweb_1   |   "number_of_data_nodes": 1,
app-sgrecweb_1   |   "active_primary_shards": 5,
app-sgrecweb_1   |   "active_shards": 5,
app-sgrecweb_1   |   "relocating_shards": 0,
app-sgrecweb_1   |   "initializing_shards": 0,
app-sgrecweb_1   |   "unassigned_shards": 5,
app-sgrecweb_1   |   "delayed_unassigned_shards": 0,
app-sgrecweb_1   |   "number_of_pending_tasks": 0,
app-sgrecweb_1   |   "number_of_in_flight_fetch": 0,
app-sgrecweb_1   |   "task_max_waiting_in_queue_millis": 0,
app-sgrecweb_1   |   "active_shards_percent_as_number": 50.0
app-sgrecweb_1   | }
app-sgrecweb_1   | 
app-sgrecweb_1   |  at org.jboss.weld.core@3.0.5.Final//org.jboss.weld.bootstrap.events.AbstractDeploymentContainerEvent.fire(AbstractDeploymentContainerEvent.java:38)
app-sgrecweb_1   |  at org.jboss.weld.core@3.0.5.Final//org.jboss.weld.bootstrap.events.AfterDeploymentValidationImpl.fire(AfterDeploymentValidationImpl.java:28)
app-sgrecweb_1   |  at org.jboss.weld.core@3.0.5.Final//org.jboss.weld.bootstrap.WeldStartup.validateBeans(WeldStartup.java:499)
app-sgrecweb_1   |  at org.jboss.weld.core@3.0.5.Final//org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:93)
app-sgrecweb_1   |  at org.jboss.as.weld@15.0.0.Final//org.jboss.as.weld.WeldStartService.start(WeldStartService.java:98)
app-sgrecweb_1   |  at org.jboss.msc@1.4.5.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1738)
app-sgrecweb_1   |  at org.jboss.msc@1.4.5.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1700)
app-sgrecweb_1   |  ... 6 more

所以这里的问题是我不知道我是否必须在开始部署应用程序之前填充 elasticsearch,或者 elasticsearch 是否应该在我部署时自动填充。 我已经在 mysql 数据库中拥有数据,并且应用程序的实体已正确定义(它们使用 lucene 来工作)。 东西不见了,我不知道是什么

您遇到的错误与您的问题无关。

您收到此错误是因为 Elasticsearch 集群的状态为 yellow,这基本上意味着没有足够的节点来复制您的索引。如果您只打算使用一个节点,那很好,您应该通过配置 属性:

告诉 Hibernate Search 状态 yellow 适合您
hibernate.search.default.elasticsearch.required_index_status yellow

关于您关于如何填充 Elasticsearch 的问题...它与 Lucene 相同。 Hibernate Search 不会在启动时执行此操作,因为这会占用大量时间和资源。您需要自己触发所谓的“大量索引”,但索引本身是自动的。参见 https://docs.jboss.org/hibernate/search/5.11/reference/en-US/html_single/#search-batchindex-massindexer