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

搞定,执行,成功

相关推荐
AOI小白新手上路19 分钟前
autodl无卡模式下载NTURain 训练集实录:基于 Git 部分克隆与稀疏检出的数据拉取
大数据·git·elasticsearch
把我格子衫拿来1 小时前
误差预算怎么做?从雅可比到蒙特卡洛的三维定位不确定度分析
python·蒙特卡洛·三维定位·误差分析·不确定度
文章永久免费只为良心1 小时前
Ctfshow_Web应用安全与防护_第二章_无字母数字命令执行
前端·python·安全·网络安全·渗透测试·ctf·红队渗透测试
2601_962885721 小时前
如何用 Python 获取上证指数、沪深300、中证500 等指数行情?
开发语言·python
昔我往昔1 小时前
LangChain_RAG_学习小结
后端·python
张张123y2 小时前
后端第六课:Python 语法速通(0 基础入门,AI 应用开发的第一门语言)
开发语言·人工智能·python·ai·后端开发
小马不起床2 小时前
Django 后端实战指南_10:用户扩展档案信息表
python·django·sqlite
Want5952 小时前
Python跳动的爱心①
开发语言·python·数学建模
SamChan902 小时前
PDF 翻译后 1,250 变成 1.250,是错了吗?用 Python 核对数字格式
python·pdf·ocr·数据校验·文档翻译
Yolanda_20222 小时前
30.利用GPU训练(一)
python