【问题标题】:Getting "illegal_argument_exception" error while loading dataset in Elasticsearch在 Elasticsearch 中加载数据集时出现“illegal_argument_exception”错误
【发布时间】:2015-12-24 20:02:51
【问题描述】:

我开始使用弹性搜索,我正在尝试使用 _bulk 方法加载 JSON 数据集。但我收到以下错误。

{
  "error" : {
    "root_cause" : [ {
      "type" : "illegal_argument_exception",
      "reason" : "Malformed action/metadata line [1], expected START_OBJECT or END_OBJECT but found [VALUE_NUMBER]"
    } ],
    "type" : "illegal_argument_exception",
    "reason" : "Malformed action/metadata line [1], expected START_OBJECT or END_OBJECT but found [VALUE_NUMBER]"
  },
  "status" : 400
}

我的 JSON 文件似乎有些问题,我验证了 JSON,似乎没问题。

这是我的示例文件。

{
"id": 3,
"customer_number": "",
"last_name": "anon",
"first_name": "zin",
"email": "anon@xyz.com",
"phone_number": "409-860-9006 x109",
"registered_at": "2007-05-02T16:27:50.74-05:00",
"last_visit_at": "2014-07-18T11:06:15-05:00",
"adcode": "",
"adcode_id": 0,
"affiliate_id": null,
"customer_type_id": 0,
"is_no_tax_customer": true,
"comments": "a",
"store_id": 5,
"source": "",
"search_string": "",
"no_account": false,
"sales_person": "SSB",
"alternate_phone_number": "800-936-9006 x109",
"is_affiliate_customer": false,
"updated_at": "2014-06-30T18:34:11.043-05:00",
"created_at": "2007-05-02T16:27:50.74-05:00",
"username": "",
"is_contact_information_only": false,
"tax_exemption_number": "",
"company": "anon",
"source_group": "",
"store_payment_methods_enabled": [0],
}

下面会提到用于发布数据的语句。

curl -XPOST 'localhost:9200/customer/_bulk?pretty' --data-binary "@account_sample.json"

谁能帮我解决这个问题?

【问题讨论】:

    标签: elasticsearch load bulkinsert


    【解决方案1】:

    只需从文件中删除最后一个逗号:

    {
    "id": 3,
    "customer_number": "",
    "last_name": "anon",
    "first_name": "zin",
    "email": "anon@xyz.com",
    "phone_number": "409-860-9006 x109",
    "registered_at": "2007-05-02T16:27:50.74-05:00",
    "last_visit_at": "2014-07-18T11:06:15-05:00",
    "adcode": "",
    "adcode_id": 0,
    "affiliate_id": null,
    "customer_type_id": 0,
    "is_no_tax_customer": true,
    "comments": "a",
    "store_id": 5,
    "source": "",
    "search_string": "",
    "no_account": false,
    "sales_person": "SSB",
    "alternate_phone_number": "800-936-9006 x109",
    "is_affiliate_customer": false,
    "updated_at": "2014-06-30T18:34:11.043-05:00",
    "created_at": "2007-05-02T16:27:50.74-05:00",
    "username": "",
    "is_contact_information_only": false,
    "tax_exemption_number": "",
    "company": "anon",
    "source_group": "",
    "store_payment_methods_enabled": [0]
    }
    

    您的文档不是有效的 json。

    【讨论】:

      【解决方案2】:

      正如错误原因所述,它期待START_OBJECT or END_OBJECT

      另外请注意,您的 JSON 不正确,因为在最后一个字段 "store_payment_methods_enabled": [0], 的末尾存在一个额外的逗号。
      您应该考虑的另一点是 JSON 中不能有结束行字符,即整个 JSON 应该是一行。

      即使您可能有一个有效的 JSON,但如果您没有提供您希望执行的操作类型(在本例中为 START_OBJECT),您将收到此错误。

      您可能需要将输入文件 account_sample.json 的内容更改为以下内容:

      { "index" : { "_index" : "someindex", "_id" : "1" } }
      {"id": 3,"customer_number": "","last_name": "anon","first_name": "zin","email": "anon@xyz.com","phone_number": "409-860-9006 x109","registered_at": "2007-05-02T16:27:50.74-05:00","last_visit_at": "2014-07-18T11:06:15-05:00","adcode": "","adcode_id": 0,"affiliate_id": null,"customer_type_id": 0,"is_no_tax_customer": true,"comments": "a","store_id": 5,"source": "","search_string": "","no_account": false,"sales_person": "SSB","alternate_phone_number": "800-936-9006 x109","is_affiliate_customer": false,"updated_at": "2014-06-30T18:34:11.043-05:00","created_at": "2007-05-02T16:27:50.74-05:00","username": "","is_contact_information_only": false,"tax_exemption_number": "","company": "anon","source_group": "","store_payment_methods_enabled": [0]}
      

      请参阅Elastic Search Bulk API 了解有关这些 API 的工作原理的更多信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-02-13
        • 2014-06-11
        • 2016-05-14
        • 1970-01-01
        • 1970-01-01
        • 2016-11-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多