简体   繁体   English

如何使用 Python 将多个文档发送到 Elasticsearch 数据流?

[英]How can I send multiple documents to Elasticsearch datastream using Python?

I am trying to index a large number of documents in Python to Elasticsearch, after reading the documentation, they refer to this example .我正在尝试将 Python 中的大量文档索引到 Elasticsearch,阅读文档后,他们参考了这个例子

This example works great when I am indexing into a normal index, however, when I try to index into a datastream, even into a brand new datastream, that can accept dynamic content, I get this error:当我对普通索引进行索引时,此示例效果很好,但是,当我尝试对可以接受动态内容的数据流,甚至是全新的数据流进行索引时,我收到此错误:

Traceback (most recent call last):
  File "/Users/Downloads/elasticsearch-py-main/examples/bulk-ingest/bulk-ingest.py", line 111, in <module>
    main()
  File "/Users/Downloads/elasticsearch-py-main/examples/bulk-ingest/bulk-ingest.py", line 102, in main
    for ok, action in bulk(
  File "/opt/homebrew/lib/python3.9/site-packages/elasticsearch/helpers/actions.py", line 524, in bulk
    for ok, item in streaming_bulk(
  File "/opt/homebrew/lib/python3.9/site-packages/elasticsearch/helpers/actions.py", line 438, in streaming_bulk
    for data, (ok, info) in zip(
  File "/opt/homebrew/lib/python3.9/site-packages/elasticsearch/helpers/actions.py", line 355, in _process_bulk_chunk
    yield from gen
  File "/opt/homebrew/lib/python3.9/site-packages/elasticsearch/helpers/actions.py", line 274, in _process_bulk_chunk_success
    raise BulkIndexError(f"{len(errors)} document(s) failed to index.", errors)
elasticsearch.helpers.BulkIndexError: 2 document(s) failed to index.

I cannot find any information on this, how can I index my data in bulk using the Elasticsearch Python connector?我找不到这方面的任何信息,如何使用 Elasticsearch Python 连接器批量索引我的数据?

This is probably because when sending documents to a data stream you need to set the action to create instead of index这可能是因为在将文档发送到数据 stream 时,您需要将操作设置为create而不是index

{ "create": {"_id": "123"}}
{ "field": "value" }

With the Python bulk helpers , you need to explicitly set '_op_type': 'create' in your bulk actions.使用Python 批量助手,您需要在批量操作中显式设置'_op_type': 'create'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用elasticsearch python中的特定字段名称从多个索引中删除文档? - How to delete documents from multiple indices using particular field name in elasticsearch python? 如何使用python访问爱思华宝服务器上的“文档”部分? - How can I access the “Documents” section on an IceWarp server using python? 如何使用Python发送电子邮件? - How can I send email using Python? 使用Python和gmail API,如何发送带有多个附件的邮件? - Using Python and gmail API, how can I send messages with multiple attachements? 使用 Python 批量更新 elasticsearch 文档 - Bulk Update for elasticsearch documents using Python 如何使用 Python 的 smpplib 将 SMS 一次发送到多个号码 - How can I send SMS to multiple numbers at one using Python's smpplib 如何使用 threadpoolexecutor 和请求在 python 中发送具有多个请求的有效负载? - how can i send payload with multiple requests in python using threadpoolexecutor and requests? 如何使用 Python 在 ElasticSearch 中搜索多个查询 - How to search for multiple queries in ElasticSearch using Python Python:我如何发送多个HTTP请求并接收响应? - Python: How can i send multiple HTTP requests and receive the response? 如何使用 Python 从 elasticsearch 删除获取的文档 - How delete fetched documents from elasticsearch with Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM