python - 使用 python elasticsearch 时出现连接错误
问题描述
我试图执行下面的python代码
from datetime import datetime
from elasticsearch import Elasticsearch
es = Elasticsearch()
es.indices.create(index='my-index', ignore=400)
通过以下连接错误的最后一条语句。
ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at
0x0000020DC5EEF6D8>: 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
0x0000020DC5EEF6D8>: Failed to establish a new connection: [WinError 10061] No
connection could be made because the target machine actively refused it)
解决方案
看来您已经安装了唯一的elasticsearch 客户端库,而没有在计算机中安装实际的 Elasticsearch。因此首先按如下方式安装 Elasticsearch。下载并安装
在你下载了一个 zip 文件(如果你使用的是 windows)之后,进入类似c:\elasticsearch-7.5.2
转到类似的路径C:\elasticsearch-7.5.2\bin
并运行elasticsearch.bat
然后转到您的浏览器并运行http://localhost:9200/,您应该得到这样的响应这意味着您的弹性实例正在运行,因此您可以继续
es.indices.create(index='my-index', ignore=400)
如果您在使用 python elasticsearch 时遇到连接错误错误,则已在此处回答
推荐阅读
- sql - 使用单列更改值评估 CASE/WHEN
- javascript - 显示从页面上的墙壁对象反弹
- python - 在 tkinter 中结合下拉菜单和复选框
- optaplanner - 输入顺序和评分
- javascript - 变量通过函数后变得未定义 - NodeJS
- visual-studio-code - 如何启用 VSCode 交互式编辑器
- python - 为什么 Pygame 在创建窗口之前要等待精灵加载?
- c++ - 无法理解函数覆盖中的这种行为
- masstransit - 中止 MassTransit Saga 的活动链
- python - AWS CDK Python - 此区域不支持终端节点配置类型 EDGE