Skip to content

Commit

Permalink
Hibernate Search documentation: take advantage of defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Jun 17, 2022
1 parent 094b352 commit 79d8867
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions docs/src/main/asciidoc/hibernate-search-orm-elasticsearch.adoc
Expand Up @@ -544,40 +544,57 @@ quarkus.ssl.native=false <1>
quarkus.datasource.db-kind=postgresql <2>
%dev.quarkus.hibernate-orm.database.generation=drop-and-create <3>
%test.quarkus.hibernate-orm.database.generation=drop-and-create <3>
quarkus.hibernate-orm.sql-load-script=import.sql <4>
quarkus.hibernate-orm.sql-load-script=import.sql <3>
quarkus.hibernate-search-orm.elasticsearch.version=7 <5>
quarkus.hibernate-search-orm.elasticsearch.analysis.configurer=bean:myAnalysisConfigurer <6>
%dev.quarkus.hibernate-search-orm.schema-management.strategy=drop-and-create <7>
%test.quarkus.hibernate-search-orm.schema-management.strategy=drop-and-create <7>
quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy=sync <8>
quarkus.hibernate-search-orm.elasticsearch.version=7 <4>
quarkus.hibernate-search-orm.elasticsearch.analysis.configurer=bean:myAnalysisConfigurer <5>
quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy=sync <6>
%prod.quarkus.datasource.jdbc.url=jdbc:postgresql://localhost/quarkus_test <9>
%prod.quarkus.datasource.jdbc.url=jdbc:postgresql://localhost/quarkus_test <7>
%prod.quarkus.datasource.username=quarkus_test
%prod.quarkus.datasource.password=quarkus_test
%prod.hibernate-search-orm.elasticsearch.hosts=localhost:9200 <9>
%prod.quarkus.hibernate-orm.database.generation=create
%prod.hibernate-search-orm.elasticsearch.hosts=localhost:9200 <7>
----
<1> We won't use SSL, so we disable it to have a more compact native executable.
<2> Let's create a PostgreSQL datasource.
<3> In dev mode and in tests, we will drop and recreate the schema on startup.
<4> We load some initial data on startup.
<5> We need to tell Hibernate Search about the version of Elasticsearch we will use.
<3> We load some initial data on startup.
<4> We need to tell Hibernate Search about the version of Elasticsearch we will use.
It is important because there are significant differences between Elasticsearch mapping syntax depending on the version.
Since the mapping is created at build time to reduce startup time, Hibernate Search cannot connect to the cluster to automatically detect the version.
Note that, for OpenSearch, you need to prefix the version with `opensearch:`; see <<opensearch>>.
<6> We point to the custom `AnalysisConfigurer` which defines the configuration of our analyzers and normalizers.
<7> In dev mode and in tests, we will drop and recreate the index on startup.
<8> This means that we wait for the entities to be searchable before considering a write complete.
<5> We point to the custom `AnalysisConfigurer` which defines the configuration of our analyzers and normalizers.
<6> This means that we wait for the entities to be searchable before considering a write complete.
On a production setup, the `write-sync` default will provide better performance.
Using `sync` is especially important when testing as you need the entities to be searchable immediately.
<9> For development and tests, we rely on <<dev-services,Dev Services>>,
<7> For development and tests, we rely on <<dev-services,Dev Services>>,
which means Quarkus will start a PostgreSQL database and Elasticsearch cluster automatically.
In production mode, however,
you will want to start a PostgreSQL database and Elasticsearch cluster manually,
which is why we provide Quarkus with this connection info in the `prod` profile (`%prod.` prefix).

[NOTE]
====
Because we rely on <<dev-services,Dev Services>>, the database and Elasticsearch schema
will automatically be dropped and re-created on each application startup
in tests and dev mode
(unless link:#quarkus-hibernate-search-orm-elasticsearch_quarkus.hibernate-search-orm.schema-management.strategy[`quarkus.hibernate-search-orm.schema-management.strategy`] is set explicitly).
If for some reason you cannot use Dev Services,
you will have to set the following properties to get similar behavior:
[source,properties]
----
%dev.quarkus.hibernate-orm.database.generation=drop-and-create
%test.quarkus.hibernate-orm.database.generation=drop-and-create
%dev.quarkus.hibernate-search-orm.schema-management.strategy=drop-and-create
%test.quarkus.hibernate-search-orm.schema-management.strategy=drop-and-create
----
See also link:#quarkus-hibernate-search-orm-elasticsearch_quarkus.hibernate-search-orm.schema-management.strategy[`quarkus.hibernate-search-orm.schema-management.strategy`].
====


[TIP]
For more information about the Hibernate Search extension configuration please refer to the <<configuration-reference, Configuration Reference>>.

Expand Down

0 comments on commit 79d8867

Please sign in to comment.