From 89b4cac8b05fdbbd5f116f4bc99e4a618302fbd9 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 17 Mar 2015 11:48:43 +0000 Subject: [PATCH] Allow Elasticsearch client-transport-sniff to be configured via the env MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../ElasticsearchAutoConfiguration.java | 1 + .../elasticsearch/ElasticsearchProperties.java | 14 ++++++++++++++ .../asciidoc/appendix-application-properties.adoc | 1 + 3 files changed, 16 insertions(+) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchAutoConfiguration.java index 094edf9b36..9a4444ad0c 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchAutoConfiguration.java @@ -87,6 +87,7 @@ public class ElasticsearchAutoConfiguration implements DisposableBean { TransportClientFactoryBean factory = new TransportClientFactoryBean(); factory.setClusterName(this.properties.getClusterName()); factory.setClusterNodes(this.properties.getClusterNodes()); + factory.setClientTransportSniff(this.properties.getClientTransportSniff()); factory.afterPropertiesSet(); TransportClient client = factory.getObject(); this.releasable = client; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchProperties.java index f3a8308b8d..a15dae26b9 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchProperties.java @@ -39,6 +39,11 @@ public class ElasticsearchProperties { */ private String clusterNodes; + /** + * Allow the client to sniff for other members of the cluster. + */ + private boolean clientTransportSniff = true; + public String getClusterName() { return this.clusterName; } @@ -54,4 +59,13 @@ public class ElasticsearchProperties { public void setClusterNodes(String clusterNodes) { this.clusterNodes = clusterNodes; } + + public boolean getClientTransportSniff() { + return this.clientTransportSniff; + } + + public void setClientTransportSniff(boolean clientTransportSniff) { + this.clientTransportSniff = clientTransportSniff; + } + } diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index e4ddffaf47..82200db115 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -349,6 +349,7 @@ content into your application; rather pick only the properties that you need. spring.data.solr.repositories.enabled=true # if spring data repository support is enabled # ELASTICSEARCH ({sc-spring-boot-autoconfigure}/elasticsearch/ElasticsearchProperties.{sc-ext}[ElasticsearchProperties]) + spring.data.elasticsearch.client-transport-sniff=true # Allow the client to sniff for other members of the cluster spring.data.elasticsearch.cluster-name= # The cluster name (defaults to elasticsearch) spring.data.elasticsearch.cluster-nodes= # The address(es) of the server node (comma-separated; if not specified starts a client node) spring.data.elasticsearch.repositories.enabled=true # if spring data repository support is enabled