使用OpenSearch Python Bulk API将数据插入多个索引
本文档显示了如何使用curl中的POST请求插入多个索引的批量数据:
如果我有这种格式的数据,则
[
{ "index": { "_index": "index-2022-06-08", "_id": "<id>" } }
{ "A JSON": "document" }
{ "index": { "_index": "index-2022-06-09", "_id": "<id>" } }
{ "A JSON": "document" }
{ "index": { "_index": "index-2022-06-10", "_id": "<id>" } }
{ "A JSON": "document" }
]
批量请求应从“ _ index”中获取索引名称:“ Index-2022-06-- 08“
我试图使用opensearch-py库进行相同的操作,但是我找不到任何示例代码段这样做。我正在使用这种格式发送AWS Lambda的请求。
client = OpenSearch(
hosts = [{'host': host, 'port': 443}],
http_auth = awsauth,
use_ssl = True,
verify_certs = True,
connection_class = RequestsHttpConnection
)
resp = helpers.bulk(client, logs, index= index_name, max_retries = 3)
在这里,我已经提到index_name作为批量请求中的参数,因此它不会从数据本身中获取index_name。如果我不提及参数中的index_name,则会丢失错误4xx index_name。
我还在研究批量API源代码: https://github.com/opensearch-project/opensearch-py/blob/main/main/opensearchpy/helpers/actions.py#l373
看来Index_name似乎不是强制性参数。
谁能帮助我,我想念什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同一问题,并在。当在
_Source-structure
中提供文档时,搜索 - 端点返回其工作。批量方法的呼叫:
其中
操作
是这样的字典列表:_OP_TYPE
可以用作定义操作的附加字段(index ,<代码>更新
,delete
,...)应为文档调用。希望这有助于遇到同一问题的任何人!
I came across the same issue and found the solution in the elasticsearch.py bulk-helpers documentation. When the documents are provided in the
_source-structure
that the search-endpoint returns it works.Call of the bulk-method:
Where
actions
is a list of dictionaries like this:_op_type
can be used as an additional field to define the action(index
,update
,delete
,...) that should be invoked for the document.Hope this helps anyone coming across the same issue!
使用以下代码希望您可以使用批量方法索引,有两种方法用于索引文档在OpenSearch中
Using the below code hope you can index using bulk method, there are two methods for indexing the documents in the opensearch one of the method is bulk method