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

搞定,执行,成功

相关推荐
暴躁小师兄数据学院22 分钟前
【AI大模型应用开发工程师特训笔记】第04讲(第9章):文件目录操作
人工智能·笔记·python
AskHarries44 分钟前
OpenClaw Skill 从哪里找
大数据·elasticsearch·搜索引擎
TechWayfarer1 小时前
IP精准定位服务在快递网点规划中的应用:如何用客户位置数据辅助选址
大数据·网络·python·tcp/ip·交通物流
CSND7401 小时前
零基础学Python合集---3:字符串的定义和常用方法
人工智能·python
五月君_1 小时前
放弃 Python,Kimi 用 TS + Node.js 重写了一个 Kimi Code
开发语言·python·node.js
还是鼠鼠1 小时前
AI掘金头条新闻系统 (Toutiao News)-获取用户信息
后端·python·mysql·fastapi·web
Cloud_Shy6182 小时前
解读《Effective Python 3rd Edition》:从练气到老魔
开发语言·python
SunnyDays10112 小时前
Python 操作 Excel 超链接:添加网页、文件、工作表和图片链接
python·excel
li星野2 小时前
RAG优化系列:HyDE(假设文档嵌入)——让LLM先写答案再检索
python·学习
知识分享小能手2 小时前
Flask入门学习教程,从入门到精通,Flask智能租房——用户中心知识点详解(9)
python·学习·flask