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

搞定,执行,成功

相关推荐
xier_ran19 分钟前
Python从入门到精通:(2)Python 核心进阶教程从数据结构到面向对象
linux·windows·python·microsoft
程序员三藏40 分钟前
接口自动化测试框架搭建详解
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·接口测试
skywalk81631 小时前
老显卡老cpu用vllm推理大模型失败Intel(R) Xeon(R) CPU E5-2643 v2
人工智能·pytorch·python·vllm
Empty_7771 小时前
Elasticsearch+Logstash+Filebeat+Kibana部署
大数据·elasticsearch·搜索引擎
程序员爱钓鱼2 小时前
Python编程实战:文件读写(文本/二进制)详解与实战
后端·python·ipython
百锦再2 小时前
第6章 结构体与方法
android·java·c++·python·rust·go
TheInk2 小时前
python学习笔记之Python基础教程(crossin全60课)
笔记·python·学习
尘缘浮梦2 小时前
RobotFramework框架环境搭建
linux·开发语言·python
程序员爱钓鱼2 小时前
Python编程实战:try...except...finally —— 让程序更稳健的异常处理机制
后端·python
岁岁岁平安2 小时前
python MongoDB 基础
数据库·python·mongodb