【问题标题】:Error inserting json file in aws elasticsearch在 aws elasticsearch 中插入 json 文件时出错
【发布时间】:2019-11-01 11:56:13
【问题描述】:

我有一个小 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
}

我做错了什么?

【问题讨论】:

    标签: amazon-web-services amazon-elasticsearch


    【解决方案1】:

    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."}
    '
    

    因此,对于您指定操作的每个文档(在本例中为索引),通过换行符终止操作,然后再次指定文档(由换行符终止)。

    【讨论】:

    • 是否有任何功能可以以所需的 json 格式(带索引)索引我的 json 文件?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-11
    • 1970-01-01
    • 2017-06-18
    • 2020-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多