我有两个不同的ElasticsearchCrudRepository接口,例如:
public interface SomeRepository extends ElasticsearchCrudRepository<SomeDao, String> {}
public interface AnotherRepository extends ElasticsearchCrudRepository<AnotherDao, String> {}
在我的配置中,我有类似的东西:
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.something")
@EnableElasticsearchRepositories(basePackages = "com.something.repos")
public class MyConfig {
@Bean
public Client client() {
InetSocketTransportAddress address = new InetSocketTransportAddress(
new InetSocketAddress('1.2.3.4',9300)
);
return TransportClient.builder().build().addTransportAddress(address);
}
@Bean
public ElasticsearchOperations elasticsearchTemplate() {
return new ElasticsearchTemplate(client());
}
}
我想要做的是让SomeRepository接口连接到服务器1.2.3.4,而AnotherRepository接口连接到不同的服务器,比如说5.6.7.8。这可能吗?
我知道我可以创建第二个elasticsearchTemplate()方法(当然具有唯一的名称)并创建一个5.6.7.8的客户端,但是我必须将ElasticsearchTemplate注入某个Service类并使用它而不是使用AnotherRepository。如果必须,我可以这样做,但我更喜欢使用存储库。
在任何地方仍无法找到任何相关信息。缺少Spring Data ES的文档是不幸的。我似乎只能找到最基本和微不足道的案例的答案,这些案件并不是必须转化为现实世界的。
有人能指出我如何使用SimpleElasticsearchRepository的工作示例吗?
答案 0 :(得分:0)
似乎不是这样做的方法。必须创建两个不同的类,它们都扩展ElasticsearchTemplate,然后在相应的Client中的Java配置传递中。