栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

已解决 | python 操作 elasticsearch TypeError:

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

已解决 | python 操作 elasticsearch TypeError:

今天在用 python 跑 elasticsearch 时,代码如下:

from elasticsearch import Elasticsearch

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

query = {
    "query": {
        "match_all": {}
    }
}

result = es.search(index="shopping", body=query)
print(result)

此时我本地 es 里是有名为 shopping 的索引的,而且索引中也有些数据,但运行时,报错如下:

C:/Users/th1nker/PycharmProjects/orders/test/test.py:3: DeprecationWarning: The 'timeout' parameter is deprecated in favor of 'request_timeout'
  es = Elasticsearch(
Traceback (most recent call last):
  File "C:/Users/th1nker/PycharmProjects/orders/test/test.py", line 3, in 
    es = Elasticsearch(
  File "C:Usersth1nkerAppDataLocalProgramsPythonPython38libsite-packageselasticsearch_syncclient__init__.py", line 331, in __init__
    node_configs = client_node_configs(
  File "C:Usersth1nkerAppDataLocalProgramsPythonPython38libsite-packageselasticsearch_syncclientutils.py", line 105, in client_node_configs
    node_configs = hosts_to_node_configs(hosts)
  File "C:Usersth1nkerAppDataLocalProgramsPythonPython38libsite-packageselasticsearch_syncclientutils.py", line 154, in hosts_to_node_configs
    node_configs.append(host_mapping_to_node_config(host))
  File "C:Usersth1nkerAppDataLocalProgramsPythonPython38libsite-packageselasticsearch_syncclientutils.py", line 221, in host_mapping_to_node_config
    return NodeConfig(**options)  # type: ignore
TypeError: __init__() missing 1 required positional argument: 'scheme'

Process finished with exit code 1

这让我有点摸不着头脑,查了网上的 python 操作 es 的入门教程,都没有提到 scheme 这个参数。

最后一想,可能是版本问题,我使用的这个 python 中的 es 库版本为 8.1.0,本地的 es 服务器版本为 8.1.1。可能是 python 中 es 版本太高的原因。于是把本地的 es 服务器版本降到 5.1.1(此时用的是 elasticsearch-rtf,该 es 版本为 5.1.1),把 python 的 es 库版本降到 5.1.0,结果就可以正常运行了。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/947903.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号