如何在python的Elasticsearch中索引大型json响应?使用Elasticsearch DSL

问题描述 投票:0回答:1

我在文档中找到了这种方法: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?

python json elasticsearch elasticsearch-dsl
1个回答
0
投票

您应该能够使用json的字典结构,而无需将所有内容都转换为DSL。只需使用普通的elasticsearch客户端即可,例如在此处查看低级客户端的示例:https://github.com/elastic/elasticsearch-py

请注意,如果您有大量文档,使用批量导入API会很有用,因为批量导入API的速度会更快。

© www.soinside.com 2019 - 2024. All rights reserved.