Python Client Failed to establish a new connection. Also Can't restart Elasticsearch

I'm following some elasticsearch-py tutorial and When I try to use elasticsearch python client to create some index, I get the following error message:

from elasticsearch import Elasticsearch
es = Elasticsearch()
from datetime import datetime
doc = {'author':'kimchy','timestamp':datetime.now()}
res = es.index(index='test-index',doc_type='tweet',id=1,body=doc)
PUT http://localhost:9200/test-index/tweet/1 [status:N/A request:2.756s]
Traceback (most recent call last):
File "C:\Program Files (x86)\python\lib\site-packages\urllib3\connection.py", line 135, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "C:\Program Files (x86)\python\lib\site-packages\urllib3\util\connection.py", line 90, in create_connection
raise err
File "C:\Program Files (x86)\python\lib\site-packages\urllib3\util\connection.py", line 80, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

Also, when I tried to restart elasticsearch, I got the following error message in the elasticsearch powershell window:

[2017-06-20T09:20:16,740][INFO ][o.e.n.Node ] [ZSbyQ6h] started
[2017-06-20T09:20:17,689][WARN ][o.e.g.GatewayAllocator$InternalPrimaryShardAllocator] [ZSbyQ6h] [metricbeat-2017.06.19]
[0]: failed to list shard for shard_started on node [ZSbyQ6hMTeWjl-mGzY_yew]
org.elasticsearch.action.FailedNodeException: Failed node [ZSbyQ6hMTeWjl-mGzY_yew]
at org.elasticsearch.action.support.nodes.TransportNodesAction$AsyncAction.onFailure(TransportNodesAction.java:2
46) [elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.action.support.nodes.TransportNodesAction$AsyncAction.access$200(TransportNodesAction.java:
160) [elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.action.support.nodes.TransportNodesAction$AsyncAction$1.handleException(TransportNodesActio
n.java:218) [elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.j
ava:1041) [elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:114
5) [elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1123) [
elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.transport.TransportService$7.onFailure(TransportService.java:638) [elasticsearch-5.4.0.jar:
5.4.0]
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.onFailure(ThreadCont
ext.java:623) [elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:39) [elasticsearch-5.4.0.
jar:5.4.0]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_131]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131]
Caused by: org.elasticsearch.transport.RemoteTransportException: [ZSbyQ6h][10.240.211.139:9300][internal:gateway/local/s
tarted_shards[n]]
Caused by: org.elasticsearch.ElasticsearchException: failed to load started shards
at org.elasticsearch.gateway.TransportNodesListGatewayStartedShards.nodeOperation(TransportNodesListGatewayStart
edShards.java:171) ~[elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.gateway.TransportNodesListGatewayStartedShards.nodeOperation(TransportNodesListGatewayStart
edShards.java:61) ~[elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.action.support.nodes.TransportNodesAction.nodeOperation(TransportNodesAction.java:145) ~[el
asticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.action.support.nodes.TransportNodesAction$NodeTransportHandler.messageReceived(TransportNod
esAction.java:269) ~[elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.action.support.nodes.TransportNodesAction$NodeTransportHandler.messageReceived(TransportNod
esAction.java:265) ~[elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) ~[e
lasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.transport.TransportService$7.doRun(TransportService.java:627) ~[elasticsearch-5.4.0.jar:5.4
.0]
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.
java:638) ~[elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-5.4.0
.jar:5.4.0]
... 3 more
Caused by: org.elasticsearch.ElasticsearchException: java.io.IOException: failed to read [id:28, legacy:false, file:C:\U
sers\amp\Desktop\elasticsearch-5.4.0\data\nodes\0\indices\X-lgi4EfT8yp7wMa5IqwBA_state\state-28.st]
at org.elasticsearch.ExceptionsHelper.maybeThrowRuntimeAndSuppress(ExceptionsHelper.java:150) ~[elasticsearch-5.
4.0.jar:5.4.0]
at org.elasticsearch.gateway.MetaDataStateFormat.loadLatestState(MetaDataStateFormat.java:334) ~[elasticsearch-5
.4.0.jar:5.4.0]
at org.elasticsearch.gateway.TransportNodesListGatewayStartedShards.nodeOperation(TransportNodesListGatewayStart
edShards.java:127) ~[elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.gateway.TransportNodesListGatewayStartedShards.nodeOperation(TransportNodesListGatewayStart
edShards.java:61) ~[elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.action.support.nodes.TransportNodesAction.nodeOperation(TransportNodesAction.java:145) ~[el
asticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.action.support.nodes.TransportNodesAction$NodeTransportHandler.messageReceived(TransportNod
esAction.java:269) ~[elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.action.support.nodes.TransportNodesAction$NodeTransportHandler.messageReceived(TransportNod
esAction.java:265) ~[elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) ~[e
lasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.transport.TransportService$7.doRun(TransportService.java:627) ~[elasticsearch-5.4.0.jar:5.4
.0]
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.
java:638) ~[elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-5.4.0
.jar:5.4.0]
... 3 more

    .......

Can anybody help me with this?

I reinstall all the related packages and the problem is gone.

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