Python查询ES错误ApiError(406, ‘Content-Type ...is not supported

现象

使用python查询es数据时出现下面错误

bash 复制代码
Traceback (most recent call last):
  File "getUsers.py", line 26, in <module>
    response = es.search(index="lizz_users", body=query)
  File "/usr/local/lib/python3.6/site-packages/elasticsearch/_sync/client/utils.py", line 402, in wrapped
    return api(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/elasticsearch/_sync/client/__init__.py", line 3734, in search
    "POST", __path, params=__query, headers=__headers, body=__body
  File "/usr/local/lib/python3.6/site-packages/elasticsearch/_sync/client/_base.py", line 321, in perform_request
    message=message, meta=meta, body=resp_body
elasticsearch.ApiError: ApiError(406, 'Content-Type header [application/vnd.elasticsearch+json; compatible-with=8] is not supported', 'Content-Type header [application/vnd.elasticsearch+json; compatible-with=8] is not supported')

原因

python安装的Elasticsearch版本与es服务的版本不一致

解决办法

查看es版本

bash 复制代码
curl  http://172.11.111.11:9200/

{
  "name" : "bike-es-ssd-1",
  "cluster_name" : "bike-user",
  "cluster_uuid" : "9QixMq6dTpeDO-WEfnq_PA",
  "version" : {
    "number" : "7.6.0",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "7f634e9f44834fbc12724506cc1da681b0c3b1e3",
    "build_date" : "2020-02-06T00:09:00.449973Z",
    "build_snapshot" : false,
    "lucene_version" : "8.4.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
  • 可以看到es版本为7.6.0

重新安装python插件

bash 复制代码
pip3 install elasticsearch==7.6.0

搞定,执行,成功

相关推荐
代码小书生7 小时前
time,一个时间操作的 Python 库!
开发语言·python·microsoft
IT策士8 小时前
Django 从 0 到 1 打造完整电商平台:收货地址管理
后端·python·django
麻雀飞吧8 小时前
TqWebHelper 本地监控:图表不刷新与端口冲突排查
前端·python
专注VB编程开发20年8 小时前
Python 的 C 扩展,本质上就是“去中心化的 COM”
java·服务器·开发语言·ide·python
TechWayfarer8 小时前
营销反作弊实战:用IP归属地查询平台识别虚假流量
网络·python·网络协议·tcp/ip·数据分析
天天爱吃肉82188 小时前
2026北京车展专题|电控产品及技术全景解读:集成化、高压化、碳化硅成主流
人工智能·python·功能测试·嵌入式硬件·汽车
biter down9 小时前
5:GUI自动化等待机制
运维·python·自动化
萌新小码农‍9 小时前
Python的input函数
java·前端·python
NiceCloud喜云9 小时前
AutoClaw 接入自定义 Anthropic 端点:让 Kanban 工作流跑在自己的模型路由上
java·开发语言·c++·人工智能·python·eclipse·batch