在Elasticsearch

时间:2015-12-24 20:02:51

标签: elasticsearch load

我开始使用弹性搜索,我正在尝试使用_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"

任何人都可以帮助我。

2 个答案:

答案 0 :(得分:0)

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

{
"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。

答案 1 :(得分:0)

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

另请注意,由于最后一个字段 "store_payment_methods_enabled": [0], 末尾有一个额外的逗号,您的 JSON 不正确。
您应该考虑的另一点是您不能在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 工作原理的更多信息。