问题描述
我不明白为什么我不能用 JSON 批量加载 Elasticsearch。我以前这样做过,但这次我完全被难住了。
我已将一组 JSON 文档处理到 Elastic Bulk Load Format 中,并且正在尝试批量加载我刚刚创建的索引(已验证创建、可查询且为空)。
{"create": {"_id": "ef68e997-c616-4b0b-b08e-dfc09f8cb08f"}}
{"id": "ef68e997-c616-4b0b-b08e-dfc09f8cb08f","title": "My document"}
... repeats for all records
我运行的命令使用指向 JSON 批量文件的路径列表和循环以使用凭据将它们卷曲/发布到 Elastic:
while IFS= read -r "path" < "${DOC_LIST_PATH}"
do
echo "Submitting Elastic formatted docs at ${path} to Elastic index 'docs' ..."
curl \
-X POST \
-H "Content-Type: application/x-ndjson" \
"https://${ES_USER}:${ES_PASSWD}@${ES_HOSTNAME}:${ES_PORT}/docs/_bulk" \
--data-binary "@${path}"
done
我之前已经完成了所有这些,它应该可以工作,但是......它没有。我收到此错误:
Submitting Elastic formatted docs at data/docs.json/part-00000.json to Elastic index 'docs' ...
Warning: Couldn't read data from file
Warning: "data/docs.json/part-00000.json",Warning: this makes an empty POST.
{"error":{"root_cause":[{"type":"parse_exception","reason":"request body is required"}],"type":"parse_exception","reason":"request body is required"},"status":400}
... repeats for all files
我发现问题在于这个 bash 代码,而不是数据或批量加载请求:
--data-binary "@${path}"
如果我用这个替换它,它会起作用:
--data-binary "@data/docs.json/part-00000.json"
为单个文件制作完整的工作命令:
curl -X POST -H "Content-Type: application/x-ndjson" "https://${ES_USER}:${ES_PASSWD}@${ES_HOSTNAME}:${ES_PORT}/docs/_bulk" --data-binary "@data/docs.json/part-00000.json"
但我需要编写脚本,所以这仍然令人抓狂。请帮忙!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)