As for spring-boot-starter-data-elasticsearch-1.5, you can achieve this with the spring el expression:
@Bean Department department() { return new Department(); } @Document(indexName="store_#{department.name()}", indexStoreType="invoice") public class InvoiceES{}
You can change the bean property to change the index you want to save / search:
invoiceRepo.save(new Invoice(...)); department.setName("newName"); invoiceRepo.save(new Invoice(...));
What should be noted is not to split this bean into multiple threads, which can ruin your index.
source share