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

搞定,执行,成功

相关推荐
用户0332126663675 分钟前
使用 Python 在 Word 文档中添加、修改和删除变量
python
专注仿真16 分钟前
动态规划算法详解
人工智能·python·大模型训练·控制算法
全栈陈序员1 小时前
【Python】基础语法入门(二十五)—— 网络编程入门:用 socket 与 requests 联网
python
adminwolf1 小时前
GoLiveChat:Open-Source Live Chat Software for Website
python
工具派2 小时前
PDF签名贴上去为什么发虚?尺寸、DPI与坐标的边界实测
java·python·pdf
谙忆2 小时前
PNG改成ICO为什么不能用:用Python检查多尺寸目录与256px帧
开发语言·python
长空任鸟飞_阿康2 小时前
如何设计支持 Skills 的 Agent?一套可扩展的四层架构
python·ai·架构·skills
滴啦嘟啦哒2 小时前
【具身笔记】【原理探究】一、对PI05源码的实践笔记
笔记·python·vla·具身
miofly2 小时前
GitHub 今日推荐|elephant-goldfish-model:先审查设计草案再写代码
python·开源·github
阿里云大数据AI技术2 小时前
云栖实录|从代码上下文到千亿级文档:Qoder × 阿里云 Elasticsearch 落地生产级Agent向量检索
人工智能·elasticsearch