【问题标题】:Elastic Search error [WinError 10061] No connection could be made because the target machine actively refused it)弹性搜索错误 [WinError 10061] 由于目标机器主动拒绝,无法建立连接)
【发布时间】:2021-01-19 22:40:50
【问题描述】:

感谢您对此进行调查,我正在尝试了解弹性搜索的基础知识,而我正在关注 This medium tutorial,因此通过执行基本的 python 脚本它给了我以下错误

raise ConnectionError("N/A", str(e), e)       
elasticsearch.exceptions.ConnectionError: 
ConnectionError(<urllib3.connection.HTTPConnection object 
at 0x00000209314C2D88>: 
Failed to establish a new 
connection: [WinError 10061] No connection could be made 
because the target machine actively refused it) caused by: 
NewConnectionError(<urllib3.connection.HTTPConnection object at 0x00000209314C2D88>: 
Failed to establish a new connection:
[WinError 10061] No connection could be made because the target machine actively refused it)

python 脚本

from elasticsearch import Elasticsearch

es = Elasticsearch([{'host':'localhost','port':9200}])

e1={
    "first_name":"nitin",
    "last_name":"panwar",
    "age": 27,
    "about": "Love to play cricket",
    "interests": ['sports','music'],
}

e2={
    "first_name" :  "Jane",
    "last_name" :   "Smith",
    "age" :         32,
    "about" :       "I like to collect rock albums",
    "interests":  [ "music" ]
}
e3={
    "first_name" :  "Douglas",
    "last_name" :   "Fir",
    "age" :         35,
    "about":        "I like to build cabinets",
    "interests":  [ "forestry" ]
}

res = es.index(index='megacorp',doc_type='employee',id=1,body=e1)
print(res['created'])

你能帮我解决这个问题吗,我还通过 pip install

安装了 elasticsearch

【问题讨论】:

  • 你能显示 curl localhost:9200 的输出吗?我希望你的 ES 和代码都在同一台机器上运行?
  • @ElasticsearchNinja 这里curl : The URI prefix is not recognized. At line:1 char:1 + curl localhost:9200 + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotImplemented: (: ) [Invoke-WebRequest], NotSupportedException + FullyQualifiedErrorId : WebCmdletIEDomNotS upportedException,Microsoft.PowerShell.Comma nds.InvokeWebRequestCommand
  • 在我的第一条评论中你到底有什么不明白的地方??
  • 什么是 curl,我需要它来运行弹性搜索吗,
  • 你在用windows吗?

标签: python elasticsearch


【解决方案1】:

在定义 es 时尝试删除 'port':9200。

替换这个:

es = Elasticsearch([{'host':'localhost','port':9200}]) 

用这个:

es = Elasticsearch([{'host':'localhost'}])

【讨论】:

    【解决方案2】:

    使用以下命令检查进程是否正在运行

    netstat -aon | findstr 9200

    这将显示 elasticsearch 正在侦听的端口和 ip。 然后你可以在浏览器上做

    localhost:9200/_cluster/health?pretty=true

    如果这显示为绿色,您就可以开始了。

    【讨论】:

    • netstat -aon | findstr 9200 没有做任何事情
    猜你喜欢
    • 1970-01-01
    • 2020-07-07
    • 2021-01-04
    • 2018-12-01
    • 2021-12-22
    • 2021-02-08
    • 2011-10-25
    • 2019-07-10
    • 1970-01-01
    相关资源
    最近更新 更多