滚动索引(动态索引名称)在Spring Data Elasticsearch中 [英] Rolling Index (Dynamic index name) In Spring Data Elasticsearch
问题描述
@Document(indexName =store_ {department},indexStoreType =invoice)
public class InvoiceES {
// fields
@Id
private String id;
@Field
私人字符串部门;
}
可以使用Spring Data来实现吗?
如果没有,是否在Spring数据的未来版本中计划?
spring-boot-starter-data-elasticsearch-1.5,你可以通过spring el表达式来实现:
@Bean
部门部门(){
return new Department();
}
@Document(indexName =store _#{department.name()},indexStoreType =invoice)
public class InvoiceES {}
您可以更改bean的属性来更改要保存/搜索的索引:
invoiceRepo.save(new Invoice(...));
department.setName(newName);
invoiceRepo.save(new Invoice(...));
应该注意的是不要在多线程中共享这个bean,这可能会弄乱你的索引。
I have a usecase wherein I want to index my document in a separate index based on certain condition. For example, I want to store invoice document to an index with department name suffixed with it.
@Document(indexName="store_{department}", indexStoreType="invoice")
public class InvoiceES{
// fields
@Id
private String id;
@Field
private String department;
}
Is it possible to achieve this using Spring Data?
If not, is it planned in coming releases of Spring Data?
As far as the spring-boot-starter-data-elasticsearch-1.5, you can achieve it by spring el expression:
@Bean
Department department() {
return new Department();
}
@Document(indexName="store_#{department.name()}", indexStoreType="invoice")
public class InvoiceES{}
You can change the bean's property to change the index you want to save/search:
invoiceRepo.save(new Invoice(...));
department.setName("newName");
invoiceRepo.save(new Invoice(...));
What should be noticed is not to share this bean in multiple thread, which may mess up your index.
这篇关于滚动索引(动态索引名称)在Spring Data Elasticsearch中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!