gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 02:36:10 26 4
gpt4 key购买 nike

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

最佳答案

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

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

关于python - 如何在python的elasticsearch中索引大型json响应?使用Elasticsearch DSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58850693/

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