bash - 是什么导致 Elasticsearch 批量加载失败?
问题描述
我不知道为什么我不能使用 JSON 批量加载 Elasticsearch。我以前做过,但这次我完全被难住了。
我已将一组 JSON 文档处理为弹性批量加载格式,并尝试批量加载我刚刚创建的索引(已验证创建,可以查询,并且为空)。
{"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"
但是我需要编写脚本,所以这仍然令人抓狂。请帮忙!
这个例子也在这里
解决方案
推荐阅读
- php - 将 Xdebug 与 Eclipse 和 XAMPP (PHP 8) 一起使用
- java - 使用 IntelliJ、OpenJFX 和 Gradle 构建 JAR 文件
- express - 使用 express-gateway 修改 graphql 查询变量
- yaml - Google Workflows 上的多行字符串插值
- c# - c# 中的 x += 1 和 x = x + 1 有什么区别吗?
- reactjs - 无法读取未定义的属性“长度”,但一直给出错误
- r - 选择带点和冒号的数字字符串
- angularjs - 将 WebSocket 与 AngularJS 一起使用
- angular - 在 Angular Slick 网格中,多选字段无法过滤
- javascript - 带有 css 生成块的 JavaScript 游戏,字符无法在点击时跳转