amazon-web-services - 在 aws elasticsearch 中插入 json 文件时出错
问题描述
我有一个小的 json 文件在 elasticsearch 中使用 t2 实例,但我无法在 aws elasticsearch 中插入数据
我的文件如下所示
[{"Company_Name": "11 plc (NGSE:MOBIL)", "Business_Description": "11 plc markets petroleum products in Nigeria."}, {"Company_Name": "3Power Energy Group, Inc. (OTCPK:PSPW)", "Business_Description": "3Power Energy Group, Inc. focuses on developing, building, and operating power plants."}, {"Company_Name": "4Sight Holdings Limited (JSE:4SI)", "Business_Description": "4Sight Holdings Limited, through its subsidiaries, provides technology support solutions across various industries in Mauritius."}, {"Company_Name": "A'ayan Leasing and Investment Company K.S.C.P. (KWSE:AAYAN)", "Business_Description": "A'ayan Leasing and Investment Company K.S.C.P. engages in financial investments, trading and investing in properties"}]
我尝试使用以下命令
curl -s -XPOST https://elasticsearchdomain/_bulk?pretty -H "Content-Type: application/x-ndjson" --data-binary '@data.json'
我收到状态 400 错误
{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "The bulk request must be terminated by a newline [\\n]"
}
],
"type" : "illegal_argument_exception",
"reason" : "The bulk request must be terminated by a newline [\\n]"
},
"status" : 400
}
我究竟做错了什么?
解决方案
Elastic Search 中的 Bulk API 并没有达到您的预期。批量 API 用于在一次 API 调用中执行多项操作(例如索引、更新、删除)。因此,您必须指定要执行的特定操作类型。在这种情况下,您要索引多个文档:
curl -X POST "localhost:9200/_bulk?pretty" -H 'Content-Type: application/json' -d'
{ "index" : { "_index" : "myindex", "_id" : "1" } }
{"Company_Name": "11 plc (NGSE:MOBIL)", "Business_Description": "11 plc markets petroleum products in Nigeria."}
{ "index" : { "_index" : "myindex", "_id" : "2" } }
{"Company_Name": "3Power Energy Group, Inc. (OTCPK:PSPW)", "Business_Description": "3Power Energy Group, Inc. focuses on developing, building, and operating power plants."}
'
因此,对于您指定操作(在本例中为索引)的每个文档,通过换行符终止操作,然后再次指定文档(由换行符终止)。
推荐阅读
- python - 使用嵌入在python字典列表中的元组列表
- c# - C#类型转换,泛型应该如何实现?
- constructor - Ue4 在运行时使用播放器启动和物理设置组件位置
- dialogflow-es - 从口语列表中获取所选项目的最佳选择?
- java - 如何递归地将字符串分成两半,然后在Java中拆分较小的字符串
- hadoop - 使用 mapreduce 查找总和为 45 的两个数
- performance - 从本地导入音频文件或使用谷歌驱动器中的链接?
- dart - 等待直到另一个异步函数完成
- r - 我应该如何在 R 中对这个简单的 for 循环进行矢量化?
- firebase - EmberJS + Firebase:返回的自定义用户信息应该更新 UI