Using Elasticsearch

Elasticsearch 是一个在数据库顶部添加搜索功能的选项。

此选项有一些限制:

  • 它只适用于SQL数据库。MongoDB和Cassandra的支持将来会被添加 (help is welcome!).
  • 您的数据库和Elasticsearch之间没有一致性,因此您可能会出现不同步的数据。这是正常的,因为Elasticsearch不是一个真正的数据库。因此,您可能需要编写一些特定的代码来同步数据, 例如使用 @Scheduled 注释,以便每天晚上运行。
    • 这也意味着如果您的数据库在应用程序之外更改,您的搜索索引将不同步。 Elasticsearch Reindexer JHipster 模块能够在这些情况下提供帮助。

When the Elasticsearch option is selected:

  • Spring Data Elasticsearch is being used, and is automatically configured by Spring Boot (here is the documentation).
  • The "repository" package has new subpackage, called "search", that holds all ElastiSearch repositories.
  • The "User" entity gets indexed in Elasticsearch, and you can query is using the /api/_search/users/:query REST endpoint.
  • When the entity sub-generator is used, the generated entity gets automatically indexed by Elasticsearch, and is used in the REST endpoint. Search capabilities are also added to the AngularJS user interface, so you can search your entity in the main CRUD screen.

Using in Development

In development, JHipster uses an embedded Elasticsearch cluster. The embedded instance is configured to store data files under the target folder, a simple ./mvn clean will destroy the persisted indices. You will need to re-index your data if this happens.

You can enable HTTP access by adding this configuration in application-dev.yml :

elasticsearch:
  properties:
      http:
          enabled: true

Using in Production

In production, JHipster expects an external Elasticsearch instance. By default, the application looks for an Elasticsearch instance running on localhost. This can be configured by using the standard Spring Boot properties, in the application-prod.yml file.

results matching ""

    No results matching ""