# restHighLevelClient connection refused

**URL:** <https://discuss.elastic.co/t/resthighlevelclient-connection-refused/183626>\
**Category:** Elasticsearch\
**Created:** [May 30, 2019, 11:25pm UTC](https://discuss.elastic.co/t/resthighlevelclient-connection-refused/183626 "2019-05-30T23:25:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![paklei](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paklei/32/47197_2.png) [@paklei](https://discuss.elastic.co/u/paklei)\
**Post date:** [May 30, 2019, 11:25pm UTC](https://discuss.elastic.co/t/resthighlevelclient-connection-refused/183626/1 "2019-05-30T23:25:38Z")

</div>

I'm trying to implement a Spring Boot app that makes a bulk insert to an Elasticsearch instance installed on a local CentOS server. The problem that appears on app log is the following:

```
 "java.net.ConnectException: Conexión rehusada
	at org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:804)
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:225)
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:212)
	at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1433)
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1403)
	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1373)
	at org.elasticsearch.client.RestHighLevelClient.bulk(RestHighLevelClient.java:477)
...
Caused by: java.net.ConnectException: Conexión rehusada
	at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
	at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
	at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvent(DefaultConnectingIOReactor.java:171)
	at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:145)
	at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:351)
	at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:221)
	at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64)
	... 1 more

```

This is my config file for the SB app:

```
@Configuration
public class ElasticsearchConfig extends AbstractFactoryBean {
	
	private static final Logger LOG = LoggerFactory.getLogger(ElasticsearchConfig.class);
	
	@Value("${elasticsearch.host}")
    private String host;
	@Value("${elasticsearch.port}")
    private int port;
    @Value("${elasticsearch.cluster-name}")
    private String clusterName;
    private RestHighLevelClient restHighLevelClient;
    
    
    
    @Override
    public void destroy() {
        try {
            if (restHighLevelClient != null) {
                restHighLevelClient.close();
            }
        } catch (final Exception e) {
            LOG.error("Error closing ElasticSearch client: ", e);
        }
    }

    @Override
    public Class<RestHighLevelClient> getObjectType() {
        return RestHighLevelClient.class;
    }

    @Override
    public boolean isSingleton() {
        return false;
    }

    @Override
    public RestHighLevelClient createInstance() {
        return buildClient();
    }

    private RestHighLevelClient buildClient() {
        try {
            restHighLevelClient = new RestHighLevelClient(
                    RestClient.builder(
                            new HttpHost(host, port, "http")));
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        return restHighLevelClient;
    }

}

```

elasticsearch.yml:

```
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: elastic-cluster
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /var/lib/elasticsearch
#
# Path to log files:
#
path.logs: /var/log/elasticsearch
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.seed_hosts: ["127.0.0.1", "[::1]"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["node1"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
http.cors.enabled: false

```

When I make a CURL GET/PUT request from the client to ES server it responses OK. Not the same on the app. I'm sure the issue is not caused by firewalld or selinux on the CentOS server because (for testing) I disabled both.

I was wondering about some default CORS config that might be cause conflicts, but not sure.  
I'm using ES 7.1.1. Java 8. Spring Boot 2.1.5

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 2, 2019, 3:17am UTC](https://discuss.elastic.co/t/resthighlevelclient-connection-refused/183626/2 "2019-06-02T03:17:20Z")

</div>

When using springboot with  
elasticsearch, you need to be explicit with some transitive dependencies as SpringBoot declares a version 6.4...

Basically you can put this in your `pom.xml`:

```auto
<properties>
  <elasticsearch.version>7.0.0<elasticsearch.version>
</properties>

```

See documentation here: [https://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html#howto-customize-dependency-versions](https://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html#howto-customize-dependency-versions)

---

<div class="post-metadata">

**Author:** ![paklei](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paklei/32/47197_2.png) [@paklei](https://discuss.elastic.co/u/paklei)\
**Post date:** [June 3, 2019, 12:50pm UTC](https://discuss.elastic.co/t/resthighlevelclient-connection-refused/183626/3 "2019-06-03T12:50:14Z")

</div>

I'm using gradle. This is my application.properties file:

```
dependencies {
	implementation 'org.elasticsearch.client:elasticsearch-rest-high-level-client:7.1.0'
	implementation 'org.elasticsearch.client:elasticsearch-rest-client:7.1.0'
	implementation 'org.elasticsearch:elasticsearch:7.1.0'
	implementation 'com.oracle:ojdbc:6'
	implementation 'org.apache.logging.log4j:log4j-api'
	implementation 'org.apache.logging.log4j:log4j-core'
	implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch'
	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 3, 2019, 2:41pm UTC](https://discuss.elastic.co/t/resthighlevelclient-connection-refused/183626/4 "2019-06-03T14:41:11Z")

</div>

Apparently according to [https://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html#howto-customize-dependency-versions](https://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html#howto-customize-dependency-versions) you should do something like this:

```auto
ext['elasticsearch.version'] = '7.1.1'

```

---

<div class="post-metadata">

**Author:** ![paklei](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paklei/32/47197_2.png) [@paklei](https://discuss.elastic.co/u/paklei)\
**Post date:** [June 3, 2019, 3:11pm UTC](https://discuss.elastic.co/t/resthighlevelclient-connection-refused/183626/5 "2019-06-03T15:11:49Z")

</div>

Same issue.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 17, 2019, 4:51pm UTC](https://discuss.elastic.co/t/resthighlevelclient-connection-refused/183626/6 "2019-06-17T16:51:06Z")

</div>

Can you print what are the values for `host` and `port`?  
Can you curl with those values from the machine which is running your spring boot code?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 15, 2019, 4:51pm UTC](https://discuss.elastic.co/t/resthighlevelclient-connection-refused/183626/7 "2019-07-15T16:51:18Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
