bug记录——python对于elasticsearch-dsl的创建mapping报错

在学习python搜索引擎中,python对于elasticsearch-dsl的创建mapping报错:elasticsearch.exceptions.RequestError: RequestError(400, ‘mapper_parsing_exception’, 'Root mapping definition has unsupported parameters: [praise_nums : {type=integer}] …
原因是:安装的elasticsearch-rtf是5.x.x的版本,默认pip install elasticsearch-dsl安装的则是7.x.x的版本。
解决办法:统一版本就可。操作如下:

  • 卸载现在安装的新版elasticsearch-dsl
    在这里插入图片描述

  • 安装5.x.x版本的elasticsearch-rtf
    在这里插入图片描述

  • python文件的代码

# -*- coding: utf-8 -*-
'''
@FileName: es_type.py
@Software: PyCharm
'''
from datetime import datetime
from elasticsearch_dsl import DocType, Date, Integer, Keyword, Text, analyzer
from elasticsearch_dsl.connections import connections

connections.create_connection(hosts=["localhost"])

class ArticleType(DocType):
    title = Text(analyzer="ik_max_word")
    create_date = Date()
    url = Keyword()
    url_object_id = Keyword()
    front_img_url = Keyword()
    front_image_path = Keyword()
    praise_nums = Integer()
    fav_nums = Integer()
    read_nums = Integer()
    content = Text(analyzer="ik_max_word")

    class Meta:
        index = "jobbole"
        doc_type = "article"

	"""
	# 这个写法是elasticsearch-dsl 7.1.0的写法
    class Index:
        name = 'jobbole'
        doc_type = "article"
        settings = {
            "number_of_shards": 6
        }

    def save(self, **kwargs):
        self.lines = len(self.body.split())
        return super(ArticleType, self).save(**kwargs)

    def is_published(self):
        return datetime.now() > self.published_from
    """

if __name__ == "__main__":
    ArticleType.init()

卡了一下午的错误,反复对照了官方文档链接: elasticsearch-dsl.readthedocs,没有问题,网上也没找到相关经验,最后才发现是版本问题。
望可以帮到像我一样的小白,免受折磨!

Pythonelasticsearch-dsl是基于elasticsearch-py封装实现的,提供了更简便的操作elasticsearch的方法。你可以通过安装elasticsearch-dsl库来使用它。安装命令是"pip install elasticsearch-dsl"。如果你在Django项目中使用elasticsearch-dsl,你还可以考虑安装django-elasticsearch-dsl-drf库,它可以将Elasticsearch DSL与Django REST框架集成,提供更方便的使用体验。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Elasticsearch python操作实践(elasticsearchElasticsearch DSL)](https://blog.csdn.net/qq_43008709/article/details/109401610)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [pythonelasticsearch_dsl模块用法详解](https://blog.csdn.net/m0_72557783/article/details/126957624)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [django-elasticsearch-dsl-drf:将Elasticsearch DSL与Django REST框架集成](https://download.csdn.net/download/weixin_42131861/15058672)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值