[英]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.