I have a SpringMvc @RestController with an indexing function.
I want a different index to be used according to the request. For example if the request parameter is "en" then the index to be used will be that. I am trying to make a multilingual index with a different analyzer per language.
As far as I have seen , I need to annotate (I am only using Java Config) my POJO with
@Document(index="en")
but how do I manage that real-time?
Option 1. ES Java client API.
You need to do it manually with
ElasticsearchClient
(ES Java client API). TheElasticsearchRepository
andElasticsearchTemplate
do not support this.Option 2. SpEL in the index name.
You can use SpEL in the index name, but you have to create indices per language yourself (e.g. on application start).
Hint: Use Index templates to reuse index settings per language.
Option 3. Custom ES template.
Alternatively, implement a custom
ElasticsearchOperations
that would identify and create indices per language for your entities dynamically. To identify the current locale either use a special property in the entity, orLocaleContextHolder
.