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 分钟前
【数据挖掘】数据挖掘综合案例—银行精准营销
人工智能·经验分享·python·数据挖掘
___波子 Pro Max.26 分钟前
GitHub Actions配置python flake8和black
python·black·flake8
阿蒙Amon1 小时前
【Python小工具】使用 OpenCV 获取视频时长的详细指南
python·opencv·音视频
HGW6892 小时前
基于 Elasticsearch 实现地图点聚合
java·elasticsearch·高德地图
橘子编程2 小时前
Python-Word文档、PPT、PDF以及Pillow处理图像详解
开发语言·python
蓝婷儿2 小时前
Python 机器学习核心入门与实战进阶 Day 2 - KNN(K-近邻算法)分类实战与调参
python·机器学习·近邻算法
之歆3 小时前
Python-封装和解构-set及操作-字典及操作-解析式生成器-内建函数迭代器-学习笔记
笔记·python·学习
天天爱吃肉82184 小时前
ZigBee通信技术全解析:从协议栈到底层实现,全方位解读物联网核心无线技术
python·嵌入式硬件·物联网·servlet
Allen_LVyingbo4 小时前
Python常用医疗AI库以及案例解析(2025年版、上)
开发语言·人工智能·python·学习·健康医疗
智能砖头4 小时前
LangChain 与 LlamaIndex 深度对比与选型指南
人工智能·python