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

标签 python json elasticsearch elasticsearch-dsl

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

相关文章:

python - 相同的函数在 Python 中以相反的顺序给出不同的结果。为什么?

python - PyInstaller: IOError: [Errno 2] 没有这样的文件或目录:

Python正则表达式困惑

java - 从 HttpURLConnection 获取数据作为文本抛出 javax.net.ssl.SSLHandshakeException for SourceForge.net

java - 如何使用 Jackson 反序列化对象数组

elasticsearch - Logstash:从一个 Elasticsearch 迁移到另一个 Elasticsearch 结果会带来一些其他属性

python - 如何在 jython/python 中解析 getAttribute (jmx) 的输出

javascript - 从 php 调用 javascript 函数不起作用

elasticsearch - ElasticSearch AND对complexType对象字段的操作

python-3.x - 在添加Python代码作为Kibana插件方面需要帮助