# Error while connecting to elasticSearch from HTTPHIghLeavelClient

**URL:** <https://discuss.elastic.co/t/error-while-connecting-to-elasticsearch-from-httphighleavelclient/178160>\
**Category:** Elasticsearch\
**Created:** [April 24, 2019, 6:07am UTC](https://discuss.elastic.co/t/error-while-connecting-to-elasticsearch-from-httphighleavelclient/178160 "2019-04-24T06:07:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaya](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@jaya](https://discuss.elastic.co/u/jaya)\
**Post date:** [April 24, 2019, 6:07am UTC](https://discuss.elastic.co/t/error-while-connecting-to-elasticsearch-from-httphighleavelclient/178160/1 "2019-04-24T06:07:34Z")

</div>

Hi,

I am getting error while connecting to elasticSearch using HighLeavelClient.  
My elastic Search instance is Running on localhost with bind and publish address 127.0.0.1:9200 and is working fine with Postman (I have created one index and added a document as well) . But when I am trying to create connection using java code using HTTPHighLevelClient I am getting "IOException java.net.ConnectException: Connection refused" error. I have tested using both localhost and 127.0.0.1 IP in code -

```auto
 new RestHighLevelClient(RestClient.builder(new HttpHost("localhost",
			 9200, "http"), new HttpHost("localhost", 9201, "http")));

```

elastic search console Logs -

```auto
[2019-04-23T10:53:34,289][WARN][o.e.x.s.a.s.m.NativeRoleMappingStore] [INGGNLAP0270] Failed to clear cache for realms [[]]
[2019-04-23T10:53:34,323][INFO][o.e.l.LicenseService] [INGGNLAP0270] license [e78802c4-9436-42a3-9a61-be9068b90684] mode [basic] - valid
[2019-04-23T10:53:34,330][INFO][o.e.g.GatewayService] [INGGNLAP0270] recovered [1] indices into cluster_state
[2019-04-23T10:53:34,704][INFO][o.e.c.r.a.AllocationService] [INGGNLAP0270] Cluster health status changed from [RED] to [YELLOW] (reason: [shards started [[audit][0]] ...]).
[2019-04-23T10:53:35,070][INFO][o.e.h.AbstractHttpServerTransport] [INGGNLAP0270] publish_address {127.0.0.1:9200}, bound_addresses {127.0.0.1:9200}, {[::1]:9200}
[2019-04-23T10:53:35,071][INFO][o.e.n.Node] [INGGNLAP0270] started

```

I checked in elasticSearch logs , I found the following -

```auto
org.elasticsearch.transport.RemoteTransportException: [][10.0.75.1:9300][internal:cluster/coordination/join]
Caused by: org.elasticsearch.cluster.coordination.CoordinationStateRejectedException: incoming term 5 does not match current term 6
	at org.elasticsearch.cluster.coordination.CoordinationState.handleJoin(CoordinationState.java:218) ~[elasticsearch-7.0.0.jar:7.0.0]
	at org.elasticsearch.cluster.coordination.Coordinator.handleJoin(Coordinator.java:940) ~[elasticsearch-7.0.0.jar:7.0.0]
	at java.util.Optional.ifPresent(Optional.java:159) ~[?:1.8.0_211]
	at org.elasticsearch.cluster.coordination.Coordinator.processJoinRequest(Coordinator.java:512) ~[elasticsearch-7.0.0.jar:7.0.0]
	at org.elasticsearch.cluster.coordination.Coordinator.handleJoinRequest(Coordinator.java:478) ~[elasticsearch-7.0.0.jar:7.0.0]
	at org.elasticsearch.cluster.coordination.JoinHelper.lambda$new$0(JoinHelper.java:124) ~[elasticsearch-7.0.0.jar:7.0.0]
	at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler$1.doRun(SecurityServerTransportInterceptor.java:251) [x-pack-security-7.0.0.jar:7.0.0]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-7.0.0.jar:7.0.0]
	at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.messageReceived(SecurityServerTransportInterceptor.java:309) [x-pack-security-7.0.0.jar:7.0.0]
	at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:63) [elasticsearch-7.0.0.jar:7.0.0]
	at org.elasticsearch.transport.TransportService$7.doRun(TransportService.java:687) [elasticsearch-7.0.0.jar:7.0.0]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:751) [elasticsearch-7.0.0.jar:7.0.0]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-7.0.0.jar:7.0.0]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_211]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_211]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_211]

```

Any Help is highly appreciated.

---

<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:** [April 24, 2019, 8:04am UTC](https://discuss.elastic.co/t/error-while-connecting-to-elasticsearch-from-httphighleavelclient/178160/2 "2019-04-24T08:04:46Z")

</div>

In case it changes anything, I'd use `127.0.0.1` instead of `localhost`.  
Not sure what is wrong though.

---

<div class="post-metadata">

**Author:** ![jaya](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@jaya](https://discuss.elastic.co/u/jaya)\
**Post date:** [April 24, 2019, 8:22am UTC](https://discuss.elastic.co/t/error-while-connecting-to-elasticsearch-from-httphighleavelclient/178160/3 "2019-04-24T08:22:03Z")

</div>

Tested it using 127.0.0.1 but getting same error "Connection Refused"

---

<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:** [April 24, 2019, 8:41am UTC](https://discuss.elastic.co/t/error-while-connecting-to-elasticsearch-from-httphighleavelclient/178160/4 "2019-04-24T08:41:44Z")

</div>

Can you just try with the low level client and share your code on GitHub then?

---

<div class="post-metadata">

**Author:** ![jaya](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@jaya](https://discuss.elastic.co/u/jaya)\
**Post date:** [May 8, 2019, 9:21am UTC](https://discuss.elastic.co/t/error-while-connecting-to-elasticsearch-from-httphighleavelclient/178160/5 "2019-05-08T09:21:42Z")

</div>

Hi , Sorry for late reply. I cannot share the code on Github. I am able to connect elasticsearch instance using spring boot project .So, I think there is some issue in permissions of my AWS lambda functions.

---

<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:** [June 5, 2019, 9:21am UTC](https://discuss.elastic.co/t/error-while-connecting-to-elasticsearch-from-httphighleavelclient/178160/6 "2019-06-05T09:21:52Z")

</div>

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