How to make Hibernate Search index name configurable at runtime

Does anyone know a good way to make the names for indices created by Hibernate Search configurable at run time? I’m using the @Indexed annotation, and it will only take a static value. It appears a configurable index name would be possible with the programmatic API, but we’ve already set up all the entities with annotations, and not eager to re-do all that configuration in a SearchMapping. Is there any way change just the index name (or even put a configurable postfix/prefix on it) while still using annotations?

The reason for this is we’d like to run several instances of the same application pointed to a shared (institutional) search server. It would help a great deal if they could be configured at runtime to use different index names.

You can combine annotation mapping with programmatic mapping. Just remove the @Indexed annotations, and set the index names using the programmatic API. Hibernate Search will use the information from both sources.

I don’t think there’s any other way to achieve what you want. If you were using the Lucene integration you could configure a different index base for each instance of your application, but I think you are using the Elasticsearch integration. In which case the easier solution would be to have multiple Elasticsearch clusters, but I reckon you cannot do that.

Excellent! I was hoping that would work, but couldn’t tell from the documentation if you could mix-and-match programmatic api and annotations or not. I’ll give it a try.