es BadRequestError问题情况

es BadRequestError问题情况

问题

bug信息

复制代码
elasticsearch.BadRequestError: BadRequestError(400, 'mapper_parsing_exception', 'failed to parse')

引起错误的代码

python 复制代码
a.save()

bug分析

一开始我以为是版本问题,但是按照配置的字段属性都是正确的,如下:

python 复制代码
# 创建document对象
class Auhtor(Document):
    id = Keyword(),
    name = Text(),
    dynasty = Integer(),
    life = Text(),
    path = Text(),
    url = Text()
    
    class Index:
        name = "author"

然后查看了一下我的数据,发现有一个NaN数据类型,这个数据类型在es中是不存在的

复制代码
id                                                         1
name                                                     武夷君
dynasty                                                    1
life       武夷君又称武夷王、武夷显道真君,是中国民间信奉的神仙之一,属于中国福建武夷山的山神、乡土神。...
path                                                     NaN
url           https://www.gushicimingju.com//shiren/wuyijun/

所以将NaN的数据进行删除

python 复制代码
df.fillna('',inplace=True)

再次运行,错误消失了

完整代码

python 复制代码
from elasticsearch_dsl import (connections,Index,Document,Text,Integer,Keyword)
import pandas as pd
# 连接es
conn = connections.create_connection(hosts=["http://localhost:9200"])

# 创建document对象
class Auhtor(Document):
    id = Keyword(),
    name = Text(),
    dynasty = Integer(),
    life = Text(),
    path = Text(),
    url = Text()
    
    class Index:
        name = "author"

# 判断索引是否存在
if Index('author').exists():
    Index('author').delete()

df = pd.read_csv('./data/author_msg.csv')
df.fillna('',inplace=True)
a_df = df.iloc[0,:]
print(a_df)

a = Auhtor(
    id = a_df['id'],
    name = a_df['name'],
    dynasty = a_df.dynasty,
    life = a_df.life,
    path = a_df.path,
    url = a_df.url,
)
# print(a.url)
a.save()
相关推荐
IT研究所6 小时前
IT 资产管理 (ITAM) 与 ITSM 协同实践:构建从资产到服务的闭环管理体系
大数据·运维·人工智能·科技·安全·低代码·自动化
辣椒种子6 小时前
Elasticsearch 基础入门--开发elasticsearch搜索数据篇
大数据·elasticsearch·jenkins
geneculture9 小时前
人机互助新时代超级个体(OPC)的学术述评——基于人文学科与数理学科的双重视域
大数据·人工智能·哲学与科学统一性·信息融智学·融智时代(杂志)
zchxzl10 小时前
亲测2026京津冀可靠广告展会
大数据·人工智能·python
J2虾虾11 小时前
在Kylin Server上安装并配置MariaDB
大数据·mariadb·kylin
Elastic 中国社区官方博客13 小时前
Elasticsearch:创建 geocoding workflow,并在 agent 中使用它进行位置搜索
大数据·人工智能·elasticsearch·搜索引擎·ai·语言模型
TechubNews14 小时前
燦谷(Cango Inc)入局AI 資本重組彰顯決心
大数据·网络·人工智能·区块链
keke.shengfengpolang14 小时前
2026大专大数据技术专业男生就业岗位全攻略:从入门到进阶
大数据
heimeiyingwang15 小时前
企业内部知识管理:AI 驱动的文档检索与知识问答
大数据
yohalaser16 小时前
硬核智测赋能 武汉曜华激光加速钙钛矿产线产业化进程
大数据·运维·人工智能