30.6.2 使用Spring Data连接Elasticsearch
为了连接Elasticsearch,你必须提供一个或者更多的集群节点的地址。可以通过设置spring.data.elasticsearch.cluster-nodes(逗号分隔的‘host:port’列表),来指定地址。当配置完成后,ElasticsearchTemplate或者TransportClient就能够像其它Spring bean一样被注入。如下所示:
spring.data.elasticsearch.cluster-nodes=localhost:9300@Component
public class MyBean {
    private final ElasticsearchTemplate template;
    public MyBean(ElasticsearchTemplate template) {
        this.template = template;
    }
    // ...
}如果你添加自己的ElasticsearchTemplate或者TransportClient @Bean,它将覆盖默认实例。
最后更新于
这有帮助吗?