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()总是抛出错误:
上面的示例来自文档,但无法正常工作。如何指定[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/