Skip to content

Commit 89b4cac

Browse files
committed
Allow Elasticsearch client-transport-sniff to be configured via the env
Previously, a TransportClient sniff property could not be configured while using Spring Boot’s Elasticsearch auto-configuration. This commit adds a new property, spring.data.elasticsearch.client-transport-sniff, that can be used to configure the TransportClient while continuing to use the auto-configuration support. Closes gh-1838
1 parent b82e220 commit 89b4cac

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchAutoConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ private Client createTransportClient() throws Exception {
8787
TransportClientFactoryBean factory = new TransportClientFactoryBean();
8888
factory.setClusterName(this.properties.getClusterName());
8989
factory.setClusterNodes(this.properties.getClusterNodes());
90+
factory.setClientTransportSniff(this.properties.getClientTransportSniff());
9091
factory.afterPropertiesSet();
9192
TransportClient client = factory.getObject();
9293
this.releasable = client;

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchProperties.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public class ElasticsearchProperties {
3939
*/
4040
private String clusterNodes;
4141

42+
/**
43+
* Allow the client to sniff for other members of the cluster.
44+
*/
45+
private boolean clientTransportSniff = true;
46+
4247
public String getClusterName() {
4348
return this.clusterName;
4449
}
@@ -54,4 +59,13 @@ public String getClusterNodes() {
5459
public void setClusterNodes(String clusterNodes) {
5560
this.clusterNodes = clusterNodes;
5661
}
62+
63+
public boolean getClientTransportSniff() {
64+
return this.clientTransportSniff;
65+
}
66+
67+
public void setClientTransportSniff(boolean clientTransportSniff) {
68+
this.clientTransportSniff = clientTransportSniff;
69+
}
70+
5771
}

spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ content into your application; rather pick only the properties that you need.
349349
spring.data.solr.repositories.enabled=true # if spring data repository support is enabled
350350
351351
# ELASTICSEARCH ({sc-spring-boot-autoconfigure}/elasticsearch/ElasticsearchProperties.{sc-ext}[ElasticsearchProperties])
352+
spring.data.elasticsearch.client-transport-sniff=true # Allow the client to sniff for other members of the cluster
352353
spring.data.elasticsearch.cluster-name= # The cluster name (defaults to elasticsearch)
353354
spring.data.elasticsearch.cluster-nodes= # The address(es) of the server node (comma-separated; if not specified starts a client node)
354355
spring.data.elasticsearch.repositories.enabled=true # if spring data repository support is enabled

0 commit comments

Comments
 (0)