【发布时间】:2022-08-15 22:59:30
【问题描述】:
本文档展示了如何在 curl 中使用 POST 请求插入具有多个索引的批量数据:https://opensearch.org/docs/latest/opensearch/index-data/
如果我有这种格式的数据,
[
{ \"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 库来做同样的事情,但我找不到任何示例 sn-p 这样做。我正在使用这种格式从 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 missing。
我也在研究批量 api 源代码:https://github.com/opensearch-project/opensearch-py/blob/main/opensearchpy/helpers/actions.py#L373
它看起来不像 index_name 是一个强制参数。
谁能帮我解决我想念的问题?
-
@Divyank 链接已死
标签: api rest elasticsearch opensearch