gpt4 book ai didi

elasticsearch - elasticsearch_dsl TypeError:index()缺少1个必需的位置参数: 'doc_type'

转载 作者:行者123 更新时间:2023-12-03 02:31:28 25 4
gpt4 key购买 nike

class Article(Document):
title = Text(analyzer='snowball', fields={'raw': Keyword()})
body = Text(analyzer='snowball')
tags = Keyword()
published_from = Date()
lines = Integer()

class Index:
name = 'blog45'
settings = {
"number_of_shards": 2,
}

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

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

# create the mappings in elasticsearch
Article.init()

# create and save and article
article = Article(meta={'id': 42}, title='Hello world!', tags=['test'])
article.body = ''' looong text '''
article.published_from = datetime.now()
article.save() ### BOMBS HERE!!! ###

我的save()总是抛出错误:

TypeError: index() missing 1 required positional argument: 'doc_type'



上面的示例来自文档,但无法正常工作。如何指定[doc_type]?

在elasticsearch-py中,
res = elastic_client.index(index="bb8_index", body=doc, doc_type='_doc')

最佳答案

截至2020年2月1日:

我将避免使用elasticsearch_dsl库,因为它无法将文档保存/索引到Elasticsearch。该库与最新的Elasticsearch(7.5+)不兼容。

使用常规的elasticsearch-py库

关于elasticsearch - elasticsearch_dsl TypeError:index()缺少1个必需的位置参数: 'doc_type',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59905567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com