我正在使用 Spring Data Elastic Search。根据请求中的不同标头,我创建 @RequestScope 对象 IndexConfig 来保存不同的索引集。似乎正在发挥作用。但我不明白单例bean DocumentA/DocumentB 如何处理动态索引?我还需要将它们设置为 @RequestScope 吗?
@Component
@Data
@RequestScope
public class IndexConfig {
private String AIndexName;
private String BIndexName;
}
@Component
public class RequestFilter implements Filter {
@Autowired
private IndexConfig indexConfig ;
public void doFilter(ServletRequest req,....) {
if(httpRequest.getHeader("one"){
indexConfig.setAIndexName("A1);
indexConfig.setBIndexName("B1);
}else if(httpRequest.getHeader("two"){
indexConfig.setAIndexName("A2);
indexConfig.setBIndexName("B2);
}
..
}
}
@Document(indexName = "#{@indexConfig.getAIndexName()}", createIndex = false)
public class DocumentA {}
@Document(indexName = "#{@indexConfig.getBIndexName()}", createIndex = false)
public class DocumentB {}
什么让你有那个想法DocumentA
or Document
B` 是单例吗?这些 e 是您存储和检索的实体。
您创建一个实例DocumentA
并通过使用以下方法存储它ElasticsearchOperations
或使用存储库功能。当从 Spring Data Elasticsearch 检索数据时,您会得到新的实例,其中填充了从 Elasticsearch 读取的数据。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)