我正在尝试将一些json数据导入我的elasticsearch实例并收到以下错误:
{
"error" : "JsonParseException[Unexpected end-of-input: expected close marker for ARRAY (from [Source: [B@7110db07; line: 1, column: 0])\n at [Source: [B@7110db07; line: 1, column: 3]]",
"status" : 500
}
我正在使用在VirtualBox上运行的Ubuntu(14.04),这是我用来导入数据的命令:
url -XPOST 'localhost:9200/mydata/fields/_bulk?pretty' --data-binary @mydata.json
这是我的JSON示例:
[
{
"field1":"sometext",
"field2":"O",
"field3":"TEXT",
"field4":"CR",
"field5":"09:38.0",
"field6":"09:38.0",
"field7":"14:13.0",
"field8":"NULL",
"field9":"NULL",
"field10":"0",
"field11":"5",
"field12":"NULL",
"field13":"NULL",
"field14":"4",
"field15":"0"
},
{
"field1":"othertext",
"field2":"O",
"field3":"TEXT",
"field4":"CR",
"field5":"09:38.0",
"field6":"09:38.0",
"field7":"14:13.0",
"field8":"NULL",
"field9":"NULL",
"field10":"0",
"field11":"5",
"field12":"NULL",
"field13":"NULL",
"field14":"4",
"field15":"0"
},
]
是否可以使用批量API导入JSON数组?
答案 0 :(得分:4)
您的json不必在批量API中包含换行符,因为API使用换行符作为分隔符。来自此处的elasticsearch文档http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html
因为这种格式使用文字\ n'作为分隔符,所以请确保 JSON操作和源代码打印效果不佳。