插入批量数据不起作用 - 弹性搜索

时间:2016-06-28 07:12:56

标签: elasticsearch kibana-4 sense

所以基本上我正在尝试新事物。这次有弹性搜索。 我已经安装了弹性和kibana,当然感觉插件。 我尝试所有基本命令,如创建索引,映射,添加文档等。 一切顺利,直到我尝试批量插入。

POST /ecommerce/product/_bulk
{"index":{"_id":"1002"}}
{"name":"SWA magazine", "price":"90.000", "description":"swa magazine description",
"status":"active", "quantity":3, "categories":[{"name":"magazine"}], 
"tags":["business", "magazine", "sales", "news"]}
{"index":{"_id":"1003"}}
{"name":"SWA magazine", "price":"90.000", "description":"swa magazine description",
"status":"active", "quantity":3, "categories":[{"name":"magazine"}], 
"tags":["business", "magazine", "sales", "news"]}

我甚至不知道我的代码有什么问题。 我总是遇到这个错误:enter image description here

请帮我解决这个问题。 非常感谢提前。

1 个答案:

答案 0 :(得分:2)

每个文档必须在一行上(即不得包含任何换行符)。像这样发送您的批量查询:

POST /ecommerce/product/_bulk
{"index":{"_id":"1002"}}
{"name":"SWA magazine", "price":"90.000", "description":"swa magazine description","status":"active", "quantity":3, "categories":[{"name":"magazine"}], "tags":["business", "magazine", "sales", "news"]}
{"index":{"_id":"1003"}}
{"name":"SWA magazine", "price":"90.000", "description":"swa magazine description", "status":"active", "quantity":3, "categories":[{"name":"magazine"}], "tags":["business", "magazine", "sales", "news"]}

粘贴在Sense中时,您应该只有1到5行,而不是1到9行。