Hibernate-ElasticSearch how to change the amount of shards and replicas

We are in the process of migrating for pure hibernate-search to hibernate-elasticsearch in order to scale our application. However we need to be able to modify the amounts of shards. Currently when setting “hibernate.search.default.sharding_strategy.nbr_of_shards = 1” in the hibernate.properties it is ignored and the default number of shards (5) on ES is used instead. I couldn’t see a reference to sharding or replication in the documentation, so I was wondering if this is possible?

The configuration property you mentioned (hibernate.search.default.sharding_strategy.nbr_of_shards) is only effective in embedded Lucene mode. It does not do anything with the experimental Elasticsearch integration of Hibernate Search 5.

Sharding and replication should be configured in Elasticsearch itself, through the index settings
There isn’t any way to customize the Elasticsearch index settings within Hibernate Search at the moment.

If you create indexes yourself through the Elasticsearch REST API, you should pass the settings in the body of your HTTP request when you create the indexes.
If you let Hibernate Search create the indexes automatically (the default), your only option is to register index templates before Hibernate Search creates the indexes, and add the relevant settings in your template(s).

I created HSEARCH-3934 to address your problem in Hibernate Search 6.

Thanks for the quick reply, seems odd that this behavior isn’t available, as everything else seems very far along! Thanks for creating the issue, look forward to seeing it implemented :slight_smile:

FYI, the Elasticsearch index settings can be customized starting with Hibernate Search 6.1:

So you can set this property:

hibernate.search.backend.schema_management.settings_file = custom/index-settings.json

And put your settings in src/main/resources/custom/index-settings.json:

{
  "number_of_shards": 1
}

See also: Hibernate Search 6.1.0.Alpha1: Reference Documentation

1 Like

Brilliant to hear! Looks like I will have to chase the team up on the migration to HS6. Thanks!