我在文档中发现了这种方法: https://elasticsearch-dsl.readthedocs.io/en/latest/index.html
class Article(Document):
title = Text(analyzer='snowball', fields={'raw': Keyword()})
body = Text(analyzer='snowball')
tags = Keyword()
published_from = Date()
lines = Integer()
像索引一样
# 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()
但是这种方法不适合我,因为我有非常大的JSON,包含超过100个字段,而且我有多个JSON,就像那样。以这种形式转换JSON是很困难的:
article = Article(meta={'id': 42}, title='Hello world!', tags=['test'])
您应该能够使用json的dict结构,而无需将所有内容转换为DSL。只需使用普通的elasticsearch客户机,例如,请参见下面的低级客户机示例:https://github.com/elastic/elasticsearch-py
请注意,如果您有大量的文档,使用批量导入API是非常有用的,它可以更快。你知道吗
相关问题 更多 >
编程相关推荐